python
config_error
ai_generated
true
fixture 'my_fixture' not found
ID: python/pytest-conftest-not-loaded
80%Fix Rate
89%Confidence
0Evidence
2024-03-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
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.
generic中文
pytest 未加载包含夹具的 conftest.py 文件。这发生在 conftest.py 位于错误目录、不在测试路径中,或 rootdir 配置错误时。
Workarounds
-
95% success
# Place conftest.py in the tests/ directory or project root # pytest automatically loads conftest.py from rootdir and test directories
-
85% success
pytest --confcutdir=tests/
Dead Ends
Common approaches that don't work:
-
75% fail
This duplicates the fixture across multiple test files and defeats the purpose of conftest.py for sharing fixtures.
-
90% fail
pytest does not load fixtures from __init__.py. Only conftest.py files are automatically loaded.