# RecursionError: 调用 Python 对象时超出最大递归深度

- **ID:** `python/pytest-collection-recursion-error`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pytest 的收集过程遍历符号链接目录，或 conftest.py 导入了一个反过来导入 pytest 的模块，导致收集期间无限递归。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.x | active | — | — |
| 8.x | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Find and remove symlink loops:

find tests -type l -exec sh -c 'readlink -f "$1" | grep -q "$(dirname $1)" && echo $1' _ {} \;
   ```
2. **** (85% 成功率)
   ```
   Break the import cycle in conftest.py by moving shared helpers into a separate module that does not import pytest.
   ```

## 无效尝试

- **** — Delays the crash and may segfault; does not fix the underlying cycle. (80% 失败率)
- **** — Only fixes one specific symlink; other cycles remain. (70% 失败率)
