# 断言错误：断言 5 == 3，'期望 5 但得到 3'

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

## 根因

断言失败，但自定义消息未显示，因为使用带有元组的普通 assert 时，pytest 不会显示消息。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   with pytest.raises(AssertionError, match='Expected 5 but got 3'):
    assert 5 == 3
   ```
2. **** (99% 成功率)
   ```
   assert 5 == 3, 'Expected 5 but got 3'
   ```

## 无效尝试

- **** — Parentheses create a tuple, which pytest interprets as a comparison, not a message. (90% 失败率)
- **** — The issue is not the f-string but the tuple; f-string still becomes a tuple element. (85% 失败率)
