python config_error ai_generated true

fixture 'db_session' not found available fixtures: cache, capfd, ...

ID: python/pytest-fixture-not-found-typo

Also available as: JSON · Markdown · 中文
80%Fix Rate
90%Confidence
0Evidence
2024-01-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.x active — — —
8.x active — — —

Root Cause

Fixture name is misspelled, defined in a conftest.py outside the test's directory scope, or not imported because the plugin is not installed.

generic

中文

Fixture 名称拼写错误,定义在测试目录范围之外的 conftest.py 中,或者因插件未安装而未导入。

Workarounds

  1. 95% success
    Create `tests/conftest.py` with `@pytest.fixture
    def db_session(): ...` and ensure tests are under `tests/`.
  2. 90% success
    `pip install pytest-django` then in pytest.ini: `[pytest]
    DJANGO_SETTINGS_MODULE = myproj.settings`

Dead Ends

Common approaches that don't work:

  1. 40% fail

    Duplicates fixture logic across many test files and defeats the purpose of shared fixtures.

  2. 90% fail

    Shadows a built-in pytest fixture and causes unexpected behavior in other tests.