# AssertionError: False 不为 true : 期望为 True

- **ID:** `python/unittest-assertion-rewrite-missing`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在 unittest 中，对假值调用 `self.assertTrue(x)` 会生成通用消息；pytest 的断言重写不适用于 unittest.TestCase 方法，因此差异不清晰。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   def test_something():
    result = compute()
    assert result == expected  # pytest shows rich diff
   ```
2. **** (85% 成功率)
   ```
   self.assertEqual(result, expected)
self.assertIn(item, container)
self.assertIsNotNone(obj)
   ```

## 无效尝试

- **** — Disables assertion rewriting entirely, making messages even less informative. (90% 失败率)
- **** — Adds noise to test output and does not fix the underlying opaque failure; CI logs become harder to scan. (60% 失败率)
- **** — Global monkeypatch affects all tests and is fragile across unittest versions. (80% 失败率)
