From 92c09d106d29dd0a5ea9539abb2099a06f46d320 Mon Sep 17 00:00:00 2001 From: Andrei Chekun Date: Fri, 24 Apr 2026 12:28:13 +0200 Subject: [PATCH] test.py: fix test collection bug In certain circumstances current way of collecting can be error prone. Collection can stop when the first file is skipped in the mode leaving the rest of the files in CLI not collected. Another issue that if the file specified twice, with directory and file explicitly, it will produce incorrect CppFile in the stash causing KeyError. Fixes: https://scylladb.atlassian.net/browse/SCYLLADB-1714 --- test/pylib/cpp/base.py | 3 +++ test/pylib/runner.py | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test/pylib/cpp/base.py b/test/pylib/cpp/base.py index df2445af51..00906b82f2 100644 --- a/test/pylib/cpp/base.py +++ b/test/pylib/cpp/base.py @@ -126,6 +126,9 @@ class CppFile(pytest.File, ABC): return args def collect(self) -> Iterator[CppTestCase]: + if BUILD_MODE not in self.stash: + return + custom_args = self.suite_config.get("custom_args", {}).get(self.test_name, DEFAULT_CUSTOM_ARGS) for test_case in self.list_test_cases(): diff --git a/test/pylib/runner.py b/test/pylib/runner.py index 147e31700d..ca3fc3f76d 100644 --- a/test/pylib/runner.py +++ b/test/pylib/runner.py @@ -163,6 +163,11 @@ def scylla_binary(testpy_test) -> Path: def pytest_collection_modifyitems(items: list[pytest.Item]) -> None: + items[:] = [ + item for item in items + if (parent_file := item.getparent(cls=pytest.File)) is not None + and BUILD_MODE in parent_file.stash + ] for item in items: modify_pytest_item(item=item) @@ -340,7 +345,8 @@ def pytest_collect_file(file_path: pathlib.Path, repeats = list(product(build_modes, parent.config.run_ids)) if not repeats: - return [] + parent.stash[REPEATING_FILES].remove(file_path) + return collectors ihook = parent.ihook collectors = list(chain(collectors, chain.from_iterable(