python
runtime_error
ai_generated
true
Fixture 'data' called directly. Fixtures are not meant to be called directly, but are provided automatically by pytest.
ID: python/pytest-fixture-return-none
80%Fix Rate
86%Confidence
0Evidence
2025-04-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
Root Cause
A test or fixture tries to call a fixture function directly (e.g., data()) instead of using it as a parameter, causing pytest to raise an error because fixtures are not regular functions.
generic中文
测试或夹具尝试直接调用夹具函数(如 data()),而不是将其作为参数使用,导致 pytest 引发错误,因为夹具不是常规函数。
Workarounds
-
95% success
Use the fixture as a parameter in the test function: def test_foo(data): instead of calling data().
-
80% success
If you need to call a fixture programmatically, use the request fixture: request.getfixturevalue('data')
Dead Ends
Common approaches that don't work:
-
70% fail
Adding a return value to the fixture does not fix the issue because the fixture is still being called incorrectly.
-
50% fail
Converting the fixture to a regular function may work but loses the benefits of fixture scoping and dependency injection.