python
runtime_error
ai_generated
true
Fixture 'db' called directly. Fixtures are not meant to be called directly
ID: python/pytest-fixture-return-not-yield
80%Fix Rate
88%Confidence
0Evidence
2025-06-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
Root Cause
在测试中直接调用fixture函数,而不是作为参数注入,导致pytest报错。
generic中文
测试中直接调用了fixture函数,而非通过参数注入。
Workarounds
-
100% success
def test_example(db): assert db is not None -
90% success
def test_example(request): db = request.getfixturevalue('db')
Dead Ends
Common approaches that don't work:
-
80% fail
失去fixture的依赖注入和清理功能。
-
90% fail
直接调用返回的是fixture对象,不是预期值。