pytest exit code 5 (no tests ran) in CI
Exit code 5 means pytest found zero tests to run. CI treats any non-zero exit as failure, so a discovery problem surfaces as a red build with no failing test.
What this error means
The pytest step fails with "Process completed with exit code 5" and "no tests ran", typically after a path, filter, or naming change hid the tests.
pytest
no tests ran in 0.01s
Error: Process completed with exit code 5.Common causes
Discovery found nothing
A wrong path, an over-narrow -k/-m filter, or misnamed files left pytest with no tests to run.
A deselect that removed every test
Marker or keyword filters can exclude all tests, yielding exit 5 even though tests exist.
How to fix it
Fix the path or filter
- Run pytest pointing at the real test directory.
- Loosen any
-k/-mfilter that deselected everything. - Confirm a non-zero collected count.
Terminal
pytest tests/ -m "not slow"Treat "no tests" as acceptable only when intended
If an empty selection is valid for a job, map exit 5 to success deliberately rather than ignoring it.
Terminal
pytest tests/ || [ "$?" -eq 5 ]How to prevent it
- Verify discovery finds tests before relying on filters.
- Keep
testpathsand naming consistent so exit 5 is meaningful. - Only suppress exit 5 where an empty run is genuinely valid.
Related guides
pytest "collected 0 items" in CIFix pytest "collected 0 items" in CI - pytest ran but discovered no tests, usually because of naming, rootdir…
pytest marker not registered (--strict-markers) in CIFix pytest "Unknown marker" under --strict-markers in CI - a custom marker is used but not declared, so stric…
pytest ModuleNotFoundError during collection in CIFix a pytest ModuleNotFoundError during collection in CI - pytest cannot import your package while loading te…