# 断言错误：断言 <Mock name='mock()' id='140735234567890'> == 5

- **ID:** `python/pytest-assert-repr-failure`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

测试将模拟对象与值进行比较，可能是因为模拟对象未设置返回值，因此默认返回另一个模拟对象。

## 版本兼容性

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

## 解决方案

1. **Set the mock's return_value to the expected integer value** (95% 成功率)
   ```
   mock = MagicMock(return_value=5)
result = mock()
assert result == 5
Or: mock.return_value = 5
   ```
2. **Ensure the code under test is calling the mock correctly** (85% 成功率)
   ```
   Debug to see if the mock is being called. If not, the test may be comparing the mock object itself instead of its return value.
   ```

## 无效尝试

- **Comparing the mock to itself using `is`** — This does not test the actual behavior; it only checks identity. (70% 失败率)
- **Setting return_value to a string like '5'** — This changes the type; the test expects an integer 5. (50% 失败率)
