python
config_error
ai_generated
true
ERROR: file or directory not found: tests/conftest.py no tests ran in 0.001s
ID: python/pytest-conftest-not-collected
80%Fix Rate
88%Confidence
0Evidence
2024-01-08First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
conftest.py is a configuration file, not a test module; pytest does not collect tests from it. Passing it explicitly on the command line produces this error.
generic中文
conftest.py 是配置文件而非测试模块;pytest 不从其中收集测试。显式在命令行传入它会产生此错误。
Workarounds
-
97% success
Run the test directory or a specific test, not conftest.py: pytest tests/ # or pytest tests/test_api.py::test_health
-
85% success
If you want to test fixture logic, move helpers to a module and import them: # tests/helpers.py def make_client(): ... # tests/test_helpers.py from tests.helpers import make_client
Dead Ends
Common approaches that don't work:
-
90% fail
Fixtures defined there are no longer auto-discovered by sibling tests; they break.
-
85% fail
pytest still ignores tests in conftest.py; behavior is undefined and confusing.