# AssertionError: assert <myapp.models.User object at 0x7f8b1c0d5e50> == <myapp.models.User object at 0x7f8b1c0d5e50>
E   AttributeError: 'User' 对象没有属性 '__eq__'

- **ID:** `python/pytest-assertion-rewrite-cache-stale`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

断言比较两个未定义 __eq__ 的对象，因此身份比较失败。令人困惑的是 pytest 的断言重写会显示 repr，使其看起来应该相等。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   class User:
    def __init__(self, id):
        self.id = id
    def __eq__(self, other):
        return isinstance(other, User) and self.id == other.id
   ```
2. **** (90% 成功率)
   ```
   assert result.id == expected.id
assert result.name == expected.name
   ```

## 无效尝试

- **** — id() comparison only checks identity; if the test intends value equality, this is a false pass. (70% 失败率)
- **** — Same identity semantics; does not fix the missing __eq__ for value comparison. (80% 失败率)
