python
runtime_error
ai_generated
true
RecursionError: 调用 Python 对象时超出最大递归深度
RecursionError: maximum recursion depth exceeded while calling a Python object
ID: python/pytest-collection-recursion-error
80%修复率
80%置信度
0证据数
2026-01-09首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
pytest 的收集过程遍历符号链接目录,或 conftest.py 导入了一个反过来导入 pytest 的模块,导致收集期间无限递归。
English
pytest's collection traverses symlinked directories or a conftest.py imports a module that imports pytest itself, causing infinite recursion during collection.
解决方案
-
90% 成功率
Find and remove symlink loops: find tests -type l -exec sh -c 'readlink -f "$1" | grep -q "$(dirname $1)" && echo $1' _ {} \; -
85% 成功率
Break the import cycle in conftest.py by moving shared helpers into a separate module that does not import pytest.
无效尝试
常见但无效的做法:
-
80% 失败
Delays the crash and may segfault; does not fix the underlying cycle.
-
70% 失败
Only fixes one specific symlink; other cycles remain.