# AssertionError: 3 != 5 : 期望 5 但得到 3

- **ID:** `python/unittest-assert-equal-order`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在 unittest 中，`assertEqual(first, second)` 报告的消息格式是 `first != second`。开发者常把消息从右往左读，从而修改了断言错误的一侧，或误以为被测函数有问题，而实际是参数顺序写反了。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Always put the actual value first and add a msg for clarity:

self.assertEqual(result, 5, f'unexpected result: {result!r}')
   ```
2. **** (98% 成功率)
   ```
   Use pytest's rich assertion rewriting instead, which prints both operands clearly:

assert result == 5
   ```

## 无效尝试

- **** — The test expectation was reversed; changing production code introduces a bug to satisfy a wrong assertion. (60% 失败率)
- **** — Silences the test and hides real regressions; the CI still reports green while behavior is wrong. (90% 失败率)
