test/pylib/runner: fix disabled file collection

Return a DisabledFile collector instead of an empty list when all modes
are disabled for a file.  Returning an empty list caused subsequent
files to not get their stash items set because file_path was never
removed from REPEATING_FILES.

Co-Authored-By: Claude Opus 4.6 (200K context) <noreply@anthropic.com>
This commit is contained in:
Evgeniy Naydanov
2026-04-28 04:18:13 +00:00
parent 43f06ed19d
commit 497bd6b6c9

View File

@@ -326,6 +326,11 @@ def pytest_configure(config: pytest.Config) -> None:
config.run_ids = tuple(range(1, repeat + 1))
class DisabledFile(pytest.File):
def collect(self) -> list[pytest.Item]:
pytest.skip("All tests in this file are disabled in requested modes according to the suite config.")
@pytest.hookimpl(wrapper=True)
def pytest_collect_file(file_path: pathlib.Path,
parent: pytest.Collector) -> Generator[None, list[pytest.Collector], list[pytest.Collector]]:
@@ -340,19 +345,17 @@ def pytest_collect_file(file_path: pathlib.Path,
mode for mode in build_modes
if not suite_config.is_test_disabled(build_mode=mode, path=file_path)
)
repeats = list(product(build_modes, parent.config.run_ids))
if not repeats:
return []
ihook = parent.ihook
collectors = list(chain(collectors, chain.from_iterable(
ihook.pytest_collect_file(file_path=file_path, parent=parent) for _ in range(1, len(repeats))
)))
for (build_mode, run_id), collector in zip(repeats, collectors, strict=True):
collector.stash[BUILD_MODE] = build_mode
collector.stash[RUN_ID] = run_id
collector.stash[TEST_SUITE] = suite_config
if repeats := list(product(build_modes, parent.config.run_ids)):
ihook = parent.ihook
collectors = list(chain(collectors, chain.from_iterable(
ihook.pytest_collect_file(file_path=file_path, parent=parent) for _ in range(1, len(repeats))
)))
for (build_mode, run_id), collector in zip(repeats, collectors, strict=True):
collector.stash[BUILD_MODE] = build_mode
collector.stash[RUN_ID] = run_id
collector.stash[TEST_SUITE] = suite_config
else:
collectors = [DisabledFile.from_parent(parent=parent, path=file_path)]
parent.stash[REPEATING_FILES].remove(file_path)