python
config_error
ai_generated
true
未找到夹具 'my_fixture'
fixture 'my_fixture' not found
ID: python/pytest-conftest-not-loaded
80%修复率
89%置信度
0证据数
2024-03-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
pytest 未加载包含夹具的 conftest.py 文件。这发生在 conftest.py 位于错误目录、不在测试路径中,或 rootdir 配置错误时。
English
pytest did not load the conftest.py file containing the fixture. This happens when conftest.py is in the wrong directory, not in the test path, or when rootdir is misconfigured.
解决方案
-
95% 成功率
# Place conftest.py in the tests/ directory or project root # pytest automatically loads conftest.py from rootdir and test directories
-
85% 成功率
pytest --confcutdir=tests/
无效尝试
常见但无效的做法:
-
75% 失败
This duplicates the fixture across multiple test files and defeats the purpose of conftest.py for sharing fixtures.
-
90% 失败
pytest does not load fixtures from __init__.py. Only conftest.py files are automatically loaded.