From 59a0a7f883d5de2e52b660778dfe3e67460c75a5 Mon Sep 17 00:00:00 2001 From: "a.berezin" Date: Mon, 7 Oct 2024 15:59:00 +0300 Subject: [PATCH 1/3] [#299] Add fuse to prevent similar names generation Signed-off-by: a.berezin --- src/frostfs_testlib/utils/string_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/frostfs_testlib/utils/string_utils.py b/src/frostfs_testlib/utils/string_utils.py index 80efa65..726c792 100644 --- a/src/frostfs_testlib/utils/string_utils.py +++ b/src/frostfs_testlib/utils/string_utils.py @@ -1,3 +1,4 @@ +import itertools import random import re import string @@ -7,6 +8,8 @@ ONLY_ASCII_LETTERS = string.ascii_letters DIGITS_AND_ASCII_LETTERS = string.ascii_letters + string.digits NON_DIGITS_AND_LETTERS = string.punctuation +FUSE = itertools.cycle(range(5)) + def unique_name(prefix: str = "", postfix: str = ""): """ @@ -18,7 +21,7 @@ def unique_name(prefix: str = "", postfix: str = ""): Returns: unique name string """ - return f"{prefix}{hex(int(datetime.now().timestamp() * 1000000))}{postfix}" + return f"{prefix}{hex(int(datetime.now().timestamp() * 1000000))}{next(FUSE)}{postfix}" def random_string(length: int = 5, source: str = ONLY_ASCII_LETTERS): -- 2.45.2 From fdc4e7a78b2d962abba08d71c502aa5ca887ab49 Mon Sep 17 00:00:00 2001 From: "a.berezin" Date: Fri, 11 Oct 2024 12:23:32 +0300 Subject: [PATCH 2/3] [#302] Autoadd marks for frostfs Signed-off-by: a.berezin --- src/frostfs_testlib/__init__.py | 1 + src/frostfs_testlib/hooks.py | 12 ++++++++++++ src/frostfs_testlib/utils/string_utils.py | 1 + 3 files changed, 14 insertions(+) create mode 100644 src/frostfs_testlib/hooks.py diff --git a/src/frostfs_testlib/__init__.py b/src/frostfs_testlib/__init__.py index f3143e6..1ceb972 100644 --- a/src/frostfs_testlib/__init__.py +++ b/src/frostfs_testlib/__init__.py @@ -1,3 +1,4 @@ __version__ = "2.0.1" from .fixtures import configure_testlib, hosting, temp_directory +from .hooks import pytest_collection_modifyitems diff --git a/src/frostfs_testlib/hooks.py b/src/frostfs_testlib/hooks.py new file mode 100644 index 0000000..df89bff --- /dev/null +++ b/src/frostfs_testlib/hooks.py @@ -0,0 +1,12 @@ +import pytest + + +@pytest.hookimpl +def pytest_collection_modifyitems(items: list[pytest.Item]): + # All tests which reside in frostfs nodeid are granted with frostfs marker, excluding + # nodeid = full path of the test + # 1. plugins + # 2. testlib itself + for item in items: + if "frostfs" in item.nodeid and "plugin" not in item.nodeid and "testlib" not in item.nodeid: + item.add_marker("frostfs") diff --git a/src/frostfs_testlib/utils/string_utils.py b/src/frostfs_testlib/utils/string_utils.py index 726c792..acbca92 100644 --- a/src/frostfs_testlib/utils/string_utils.py +++ b/src/frostfs_testlib/utils/string_utils.py @@ -8,6 +8,7 @@ ONLY_ASCII_LETTERS = string.ascii_letters DIGITS_AND_ASCII_LETTERS = string.ascii_letters + string.digits NON_DIGITS_AND_LETTERS = string.punctuation +# if unique_name is called multiple times within the same microsecond, append 0-4 to the name so it surely unique FUSE = itertools.cycle(range(5)) -- 2.45.2 From 3219dd63891d5ae2e4fb76ecdbfd9dec72173a77 Mon Sep 17 00:00:00 2001 From: "a.berezin" Date: Fri, 25 Oct 2024 18:52:43 +0300 Subject: [PATCH 3/3] [#310] Update test marking Signed-off-by: a.berezin --- src/frostfs_testlib/hooks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/frostfs_testlib/hooks.py b/src/frostfs_testlib/hooks.py index df89bff..6830e78 100644 --- a/src/frostfs_testlib/hooks.py +++ b/src/frostfs_testlib/hooks.py @@ -8,5 +8,6 @@ def pytest_collection_modifyitems(items: list[pytest.Item]): # 1. plugins # 2. testlib itself for item in items: - if "frostfs" in item.nodeid and "plugin" not in item.nodeid and "testlib" not in item.nodeid: + location = item.location[0] + if "frostfs" in location and "plugin" not in location and "testlib" not in location: item.add_marker("frostfs") -- 2.45.2