python
runtime_error
ai_generated
true
失败:FAILED test_function - 断言错误:自定义消息
Failed: FAILED test_function - AssertionError: custom message
ID: python/pytest-fail-exception
80%修复率
85%置信度
0证据数
2024-07-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
使用pytest.fail()或断言失败时,pytest抛出Failed异常,测试停止。
English
使用pytest.fail()或断言失败时,pytest抛出Failed异常,测试停止。
解决方案
-
90% 成功率
pytest.fail("原因: " + str(detail)) -
80% 成功率
if not condition: pytest.skip('跳过原因')
无效尝试
常见但无效的做法:
-
70% 失败
Failed是pytest内部异常,捕获后测试仍会失败
-
50% 失败
assert信息不如pytest.fail清晰