# 失败：FAILED test_function - 断言错误：自定义消息

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

## 根因

使用pytest.fail()或断言失败时，pytest抛出Failed异常，测试停止。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   pytest.fail("原因: " + str(detail))
   ```
2. **** (80% 成功率)
   ```
   if not condition:
    pytest.skip('跳过原因')
   ```

## 无效尝试

- **** — Failed是pytest内部异常，捕获后测试仍会失败 (70% 失败率)
- **** — assert信息不如pytest.fail清晰 (50% 失败率)
