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
This commit is contained in:
Andrei Chekun
2026-04-24 12:28:13 +02:00
parent 70261dc674
commit 92c09d106d
2 changed files with 10 additions and 1 deletions

View File

@@ -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():

View File

@@ -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(