pytest Exit Codes 0-5 in CI: Meaning of Each Status
pytest defines exit codes 0 through 5, each meaning something specific - including code 5 for "no tests collected".
Unlike most tools, pytest assigns a distinct meaning to each of its exit codes, so the number tells you precisely what happened.
What it means
0 = all tests passed; 1 = some tests failed; 2 = interrupted (e.g. Ctrl-C); 3 = an internal pytest error; 4 = a command-line usage error; 5 = no tests were collected.
Common causes
- Exit 5: wrong
testpaths/rootdir or files not namedtest_*.py. - Exit 4: a bad CLI flag or option.
- Exit 2: the run was cancelled or a fixture aborted it.
How to fix it
Map the code to its meaning, then act: for 5, fix discovery (paths, naming, conftest.py); for 4, fix the invocation; for 1, read the failing assertions. These are deterministic test outcomes, not transient.
Related guides
Exit Codes and Signals in CI/CD: A Practical GuideA practical guide to process exit codes and signals in CI/CD - what 1, 2, 124, 126, 127, 130, 137, and 143 me…
CI Exit Code Lookup: What Does This Exit Code Mean?Instant lookup for CI/CD process exit codes - enter a code (137, 127, 143…) to see what it means, whether it…