python
runtime_error
ai_generated
true
fixture 'db'被直接调用。fixture不应被直接调用
Fixture 'db' called directly. Fixtures are not meant to be called directly
ID: python/pytest-fixture-return-not-yield
80%修复率
88%置信度
0证据数
2025-06-30首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
根因分析
测试中直接调用了fixture函数,而非通过参数注入。
English
在测试中直接调用fixture函数,而不是作为参数注入,导致pytest报错。
解决方案
-
100% 成功率
def test_example(db): assert db is not None -
90% 成功率
def test_example(request): db = request.getfixturevalue('db')
无效尝试
常见但无效的做法:
-
80% 失败
失去fixture的依赖注入和清理功能。
-
90% 失败
直接调用返回的是fixture对象,不是预期值。