# RecursionError：调用 Python 对象时超出最大递归深度
（在对自引用对象进行断言内省期间）

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

## 根因

在 assert 中比较的对象具有无限递归的 __repr__（例如子节点包含自身的树节点），而 pytest 的断言重写调用 repr 生成差异。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   class Node:
    def __repr__(self):
        return f"Node(id={id(self)}, value={self.value!r})"
   ```
2. **** (90% 成功率)
   ```
   assert node.value == expected.value
assert node.parent_id == expected.parent_id
   ```

## 无效尝试

- **** — May segfault the interpreter and doesn't fix the cyclic repr. (90% 失败率)
- **** — Silently passes tests; hides real failures. (95% 失败率)
- **** — Loses all diff quality; the repr still recurses when printed. (70% 失败率)
