python
runtime_error
ai_generated
true
Failed: FAILED test_function - AssertionError: custom message
ID: python/pytest-fail-exception
80%Fix Rate
85%Confidence
0Evidence
2024-07-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
使用pytest.fail()或断言失败时,pytest抛出Failed异常,测试停止。
generic中文
使用pytest.fail()或断言失败时,pytest抛出Failed异常,测试停止。
Workarounds
-
90% success
pytest.fail("原因: " + str(detail)) -
80% success
if not condition: pytest.skip('跳过原因')
Dead Ends
Common approaches that don't work:
-
70% fail
Failed是pytest内部异常,捕获后测试仍会失败
-
50% fail
assert信息不如pytest.fail清晰