# 断言错误：assert False + True == True（pytest 断言重写失败）

- **ID:** `python/pytest-assertion-rewriting-failure`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

由于复杂表达式或对非布尔值使用 'is' 运算符，pytest 的断言重写机制未能正确重写断言。

## 版本兼容性

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

## 解决方案

1. **Simplify the assertion into multiple steps for better rewriting.** (90% 成功率)
   ```
   result = False + True; assert result == True
   ```
2. **Use explicit comparison with '==' instead of 'is' for value equality.** (85% 成功率)
   ```
   assert (False + True) == True  # instead of 'is True'
   ```

## 无效尝试

- **Adding more assertions to debug the expression** — The rewriting issue persists for similar complex expressions. (70% 失败率)
- **Disabling assertion rewriting globally with -O flag** — This removes all assertion checks, which is not desirable for testing. (60% 失败率)
