python
config_error
ai_generated
true
ERROR: 找不到文件或目录: tests/conftest.py 0.001s 内未运行测试
ERROR: file or directory not found: tests/conftest.py no tests ran in 0.001s
ID: python/pytest-conftest-not-collected
80%修复率
88%置信度
0证据数
2024-01-08首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
conftest.py 是配置文件而非测试模块;pytest 不从其中收集测试。显式在命令行传入它会产生此错误。
English
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.
解决方案
-
97% 成功率
Run the test directory or a specific test, not conftest.py: pytest tests/ # or pytest tests/test_api.py::test_health
-
85% 成功率
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
无效尝试
常见但无效的做法:
-
90% 失败
Fixtures defined there are no longer auto-discovered by sibling tests; they break.
-
85% 失败
pytest still ignores tests in conftest.py; behavior is undefined and confusing.