python
runtime_error
ai_generated
true
RecursionError: maximum recursion depth exceeded
ID: python/pytest-recursion-error-fixture
80%Fix Rate
85%Confidence
0Evidence
2024-11-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
A fixture depends on itself directly or indirectly (e.g., `def a(b): ...` and `def b(a): ...`), causing infinite recursion during fixture resolution.
generic中文
fixture 直接或间接依赖自身(例如 `def a(b): ...` 和 `def b(a): ...`),导致 fixture 解析期间无限递归。
Workarounds
-
85% success
@pytest.fixture def a(request): b = request.getfixturevalue('b') ... -
95% success
def _common_setup(): ... @pytest.fixture def a(): return _common_setup() @pytest.fixture def b(): return _common_setup()
Dead Ends
Common approaches that don't work:
-
90% fail
Delays the crash and may cause a segfault; does not fix the circular dependency.
-
60% fail
If the dependency is intentional, renaming breaks the chain; if not, it may still be circular.