Skip to content
Latchkey

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

  1. Run pytest pointing at the real test directory.
  2. Loosen any -k/-m filter that deselected everything.
  3. 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 testpaths and naming consistent so exit 5 is meaningful.
  • Only suppress exit 5 where an empty run is genuinely valid.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →