python
config_error
ai_generated
true
no tests ran in 0.12s ERROR: file or directory not found: tests/test_api.py
ID: python/pytest-exit-code-5-no-tests-collected
80%Fix Rate
90%Confidence
0Evidence
2024-04-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
The path passed to pytest does not exist relative to the current working directory, or the test file was renamed/moved. pytest exits with code 5 (EXIT_NOTESTSCOLLECTED) when no tests are collected.
generic中文
传给 pytest 的路径相对于当前工作目录不存在,或测试文件被重命名/移动。当未收集到测试时,pytest 以代码 5(EXIT_NOTESTSCOLLECTED)退出。
Workarounds
-
92% success
cd /app && pytest
-
88% success
test -f tests/test_api.py && pytest tests/test_api.py || echo 'missing test file'
Dead Ends
Common approaches that don't work:
-
90% fail
Ignoring the directory means the intended tests never run; the CI job passes green while testing nothing.
-
85% fail
Masks genuinely missing tests and broken collection, allowing regressions through.