Skip to content

Commit fa7f56d

Browse files
committed
Assert pytest collection succeeded in custom linter fixture
Previously the return code of pytest.main() was discarded, so a collection error (import failure, syntax error) would silently leave the fixture with whatever items were captured before the crash. Assert the exit code is OK so collection errors fail the meta-tests loudly.
1 parent 65a6322 commit fa7f56d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

ci/test_custom_linters.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def all_tests() -> frozenset[str]:
4343
``capsys`` would see an empty string and the test would pass vacuously.
4444
"""
4545
plugin = _CollectPlugin()
46-
pytest.main(
46+
exit_code = pytest.main(
4747
args=[
4848
"--collect-only",
4949
# Disable pytest-retry to avoid:
@@ -61,6 +61,12 @@ def all_tests() -> frozenset[str]:
6161
],
6262
plugins=[plugin],
6363
)
64+
# Fail loudly on collection errors (import failures, syntax errors, etc.)
65+
# rather than silently using whatever items were captured before the
66+
# crash.
67+
assert exit_code == pytest.ExitCode.OK, (
68+
f"Collection failed with exit code {exit_code}."
69+
)
6470
return frozenset(plugin.nodeids)
6571

6672

0 commit comments

Comments
 (0)