python config_error ai_generated true

no tests ran in 0.00s ERROR: file or directory not found: tests/

ID: python/pytest-exit-code-no-tests-collected

Also available as: JSON · Markdown · 中文
80%Fix Rate
90%Confidence
0Evidence
2024-12-02First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.x active — — —
8.x active — — —

Root Cause

The path passed to pytest does not exist relative to the current working directory. Often happens in CI when the working directory is the repo root but tests live in a sub-package, or when a Makefile changes directory.

generic

中文

传给 pytest 的路径相对于当前工作目录不存在。常发生在 CI 中:工作目录是仓库根,但测试位于子包中,或者 Makefile 切换了目录。

Workarounds

  1. 95% success
    Verify the path and use the full path:
    
    pytest ./backend/tests
  2. 95% success
    Set testpaths in config so pytest finds the right directory regardless of cwd:
    
    # pyproject.toml
    [tool.pytest.ini_options]
    testpaths = ["backend/tests"]

Dead Ends

Common approaches that don't work:

  1. 50% fail

    May collect unrelated tests or fail to find anything if rootdir is misconfigured.

  2. 90% fail

    Silences the error but runs zero tests, causing CI to pass green with no coverage.