python
runtime_error
ai_generated
true
递归错误:在 conftest.py 中调用 Python 对象时超出最大递归深度
RecursionError: maximum recursion depth exceeded while calling a Python object in conftest.py
ID: python/pytest-conftest-recursion-error
80%修复率
82%置信度
0证据数
2024-09-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
根因分析
conftest.py 中的夹具在没有基本情况的情况下递归调用自身,通常是由于循环依赖或夹具设置中的无限循环。
English
A fixture in conftest.py is calling itself recursively without a base case, often due to circular dependency or infinite loop in fixture setup.
解决方案
-
85% 成功率 Identify and break the circular dependency by restructuring fixtures.
Refactor conftest.py to avoid fixture A calling fixture B that calls fixture A again.
-
80% 成功率 Use 'yield' fixtures with proper teardown to avoid recursive setup.
Change fixture to use yield instead of return to ensure cleanup breaks recursion.
无效尝试
常见但无效的做法:
-
Increasing recursion limit with sys.setrecursionlimit
70% 失败
This only delays the crash; the infinite loop still exists and may exhaust memory.
-
Removing all fixtures from conftest.py
80% 失败
Tests that depend on those fixtures will fail with missing fixture errors.