pytest collected zero tests

pytest exited with code 5 because it collected zero tests.

pytest-no-tests medium confidence test python

Matched signals

  • collected 0 items
  • no tests ran
  • exit code: 5
  • exit code 5
  • ExitCode.NO_TESTS_COLLECTED
  • no tests were run
  • ERROR: not found:
  • collected 0 items / 1 error

pytest collected zero tests

What this failure means

pytest exited with code 5 because it collected zero tests. No tests matched the given path, filter expression, or marker constraint.

Symptoms

Faultline looks for one or more of these log fragments:

collected 0 items
no tests ran
exit code: 5
exit code 5
ExitCode.NO_TESTS_COLLECTED
no tests were run
ERROR: not found:
collected 0 items / 1 error

Diagnosis

pytest reserves exit code 5 for the specific condition where it starts successfully, finishes collection, and finds nothing to run. This is distinct from a collection error (exit code 2) or a test failure (exit code 1).

Common causes:

  • The test path passed to pytest does not match any test files or functions.
  • A -k expression or -m marker filter excludes every collected item.
  • Test files exist but do not match the configured python_files or python_functions glob patterns.
  • The working directory is wrong so pytest cannot discover the test root.
  • testpaths in pytest.ini or pyproject.toml points at a non-existent directory, or the test directory was not checked out by a shallow clone.

Fix steps

  1. Run collection in dry-run mode to see what pytest discovers:

    pytest --collect-only
    
  2. If using a path argument, confirm the path exists and contains test files prefixed test_ or suffixed _test.py.

  3. Check for an overly restrictive -k or -m filter in the pytest invocation or in addopts inside pytest.ini / pyproject.toml:

    # pyproject.toml — watch for addopts entries that exclude by default
    [tool.pytest.ini_options]
    addopts = "-m not slow"
    
  4. Verify testpaths points at the correct directory:

    python -m pytest --co -q 2>&1 | head -20
    
  5. If the test directory requires generation or exists only on certain branches, ensure the CI job checks it out before running pytest.

Validation

  • pytest --collect-only returns at least one test item with exit code 0.
  • pytest exits with code 0 (tests ran) rather than code 5 (nothing collected).

Try it locally

pytest --collect-only
pytest --co -q
pytest --collect-only

How Faultline detects it

Use faultline explain pytest-no-tests to see the full playbook.

faultline analyze build.log
faultline explain pytest-no-tests

Generated from playbooks/bundled/log/test/pytest-no-tests.yaml. Do not edit directly.

Try it on your own failed log

$ faultline analyze failed.log
Want this across every CI run? Faultline Teams tracks recurring failures across all your repos and surfaces patterns in a shared dashboard.