python config_error ai_generated true

pytest.skip: Skipped: condition not met

ID: python/pytest-skip-vs-xfail-confusion

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-05-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.x active
8.x active

Root Cause

A test was skipped using pytest.skip() when the developer intended to mark it as expected to fail (xfail). The test is not run, but the failure is not tracked.

generic

中文

开发者使用 pytest.skip() 跳过测试,但本意是标记为预期失败(xfail)。测试未运行,但失败未被跟踪。

Workarounds

  1. 95% success
    @pytest.mark.xfail(reason='Known bug #123')
    def test_broken():
        assert False
  2. 90% success
    def test_conditional():
        if not feature_enabled():
            pytest.xfail('Feature not enabled')
        assert feature_works()

Dead Ends

Common approaches that don't work:

  1. 80% fail

    pytest.xfail immediately fails the test, which is not the same as marking it as expected to fail. The test will be reported as failed.

  2. 95% fail

    Comments do not change test behavior. The test remains skipped and the expected failure is not tracked.