# AssertionError: assert {'a': 1} == {'a': 1}
  省略 1 个相同项，使用 -vv 显示
  完整差异:
  - {'a': 1}
  + {'a': 1}
  ?  ^   ^
  + {'a': 1}
  ?  ^   ^

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

## 根因

断言比较的对象在 repr 中看似相等，但在类型或嵌套标识上不同（如 int 与 bool、numpy 数组与 list，或自定义 __eq__ 返回非布尔值）。pytest 的断言重写隐藏了真实差异。

## 版本兼容性

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

## 解决方案

1. **** (85% 成功率)
   ```
   Print the types and use a type-strict comparison:

def test_x():
    actual = get()
    assert type(actual) is dict and actual == {'a': 1}, f"{type(actual)=} {actual=}"
   ```
2. **** (92% 成功率)
   ```
   For numpy/pandas, use the dedicated assertion helpers:

import numpy as np
np.testing.assert_array_equal(actual, expected)
import pandas as pd
pd.testing.assert_frame_equal(df1, df2)
   ```

## 无效尝试

- **** — Identity comparison almost always fails for equal-but-distinct objects and produces a more confusing error. (85% 失败率)
- **** — Only changes the error formatting; the underlying inequality is still there. (90% 失败率)
