# 递归错误：在 conftest.py 中调用 Python 对象时超出最大递归深度

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

## 根因

conftest.py 中的夹具在没有基本情况的情况下递归调用自身，通常是由于循环依赖或夹具设置中的无限循环。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.9 | active | — | — |
| 3.10 | active | — | — |

## 解决方案

1. **Identify and break the circular dependency by restructuring fixtures.** (85% 成功率)
   ```
   Refactor conftest.py to avoid fixture A calling fixture B that calls fixture A again.
   ```
2. **Use 'yield' fixtures with proper teardown to avoid recursive setup.** (80% 成功率)
   ```
   Change fixture to use yield instead of return to ensure cleanup breaks recursion.
   ```

## 无效尝试

- **Increasing recursion limit with sys.setrecursionlimit** — This only delays the crash; the infinite loop still exists and may exhaust memory. (70% 失败率)
- **Removing all fixtures from conftest.py** — Tests that depend on those fixtures will fail with missing fixture errors. (80% 失败率)
