python
runtime_error
ai_generated
true
RecursionError: 超出最大递归深度
RecursionError: maximum recursion depth exceeded
ID: python/pytest-recursion-error-fixture
80%修复率
85%置信度
0证据数
2024-11-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
fixture 直接或间接依赖自身(例如 `def a(b): ...` 和 `def b(a): ...`),导致 fixture 解析期间无限递归。
English
A fixture depends on itself directly or indirectly (e.g., `def a(b): ...` and `def b(a): ...`), causing infinite recursion during fixture resolution.
解决方案
-
85% 成功率
@pytest.fixture def a(request): b = request.getfixturevalue('b') ... -
95% 成功率
def _common_setup(): ... @pytest.fixture def a(): return _common_setup() @pytest.fixture def b(): return _common_setup()
无效尝试
常见但无效的做法:
-
90% 失败
Delays the crash and may cause a segfault; does not fix the circular dependency.
-
60% 失败
If the dependency is intentional, renaming breaks the chain; if not, it may still be circular.