python
config_error
ai_generated
true
fixture 'db_session' 未找到 可用 fixtures: cache, capfd, ...
fixture 'db_session' not found available fixtures: cache, capfd, ...
ID: python/pytest-fixture-not-found-typo
80%修复率
90%置信度
0证据数
2024-01-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
Fixture 名称拼写错误,定义在测试目录范围之外的 conftest.py 中,或者因插件未安装而未导入。
English
Fixture name is misspelled, defined in a conftest.py outside the test's directory scope, or not imported because the plugin is not installed.
解决方案
-
95% 成功率
Create `tests/conftest.py` with `@pytest.fixture def db_session(): ...` and ensure tests are under `tests/`.
-
90% 成功率
`pip install pytest-django` then in pytest.ini: `[pytest] DJANGO_SETTINGS_MODULE = myproj.settings`
无效尝试
常见但无效的做法:
-
40% 失败
Duplicates fixture logic across many test files and defeats the purpose of shared fixtures.
-
90% 失败
Shadows a built-in pytest fixture and causes unexpected behavior in other tests.