python runtime_error ai_generated true

Failed: FAILED test_function - AssertionError: custom message

ID: python/pytest-fail-exception

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-07-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.x active
8.x active

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Failed是pytest内部异常,捕获后测试仍会失败

  2. 50% fail

    assert信息不如pytest.fail清晰