python config_error ai_generated true

fixture 'my_fixture' not found

ID: python/pytest-conftest-not-loaded

Also available as: JSON · Markdown · 中文
80%Fix Rate
89%Confidence
0Evidence
2024-03-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 95% success
    # Place conftest.py in the tests/ directory or project root
    # pytest automatically loads conftest.py from rootdir and test directories
  2. 85% success
    pytest --confcutdir=tests/

Dead Ends

Common approaches that don't work:

  1. 75% fail

    This duplicates the fixture across multiple test files and defeats the purpose of conftest.py for sharing fixtures.

  2. 90% fail

    pytest does not load fixtures from __init__.py. Only conftest.py files are automatically loaded.