# pytest.fail() 被调用但未提供消息；请使用 pytest.fail(reason='...')

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

## 根因

在较新的 pytest 版本中，调用 pytest.fail() 而不提供 reason 参数已被弃用或引发错误，以强制提供描述性的失败消息。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Always provide a reason: pytest.fail(reason='Expected condition not met')
   ```
2. **** (90% 成功率)
   ```
   Use pytest.fail('message') as a positional argument, which is equivalent to pytest.fail(reason='message').
   ```

## 无效尝试

- **** — Using a bare raise or assert False may work but loses the structured failure reporting of pytest. (50% 失败率)
- **** — Ignoring the warning and continuing to use pytest.fail() without argument may cause test failures in future pytest versions. (60% 失败率)
