python
runtime_error
ai_generated
true
RecursionError: maximum recursion depth exceeded while calling a Python object
ID: python/pytest-collection-recursion-error
80%Fix Rate
80%Confidence
0Evidence
2026-01-09First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
pytest's collection traverses symlinked directories or a conftest.py imports a module that imports pytest itself, causing infinite recursion during collection.
generic中文
pytest 的收集过程遍历符号链接目录,或 conftest.py 导入了一个反过来导入 pytest 的模块,导致收集期间无限递归。
Workarounds
-
90% success
Find and remove symlink loops: find tests -type l -exec sh -c 'readlink -f "$1" | grep -q "$(dirname $1)" && echo $1' _ {} \; -
85% success
Break the import cycle in conftest.py by moving shared helpers into a separate module that does not import pytest.
Dead Ends
Common approaches that don't work:
-
80% fail
Delays the crash and may segfault; does not fix the underlying cycle.
-
70% fail
Only fixes one specific symlink; other cycles remain.