python config_error ai_generated true

pytest.skip: 跳过: 条件未满足

pytest.skip: Skipped: condition not met

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

其他格式: JSON · Markdown 中文 · English
80%修复率
86%置信度
0证据数
2024-05-22首次发现

版本兼容性

版本状态引入弃用备注
7.x active
8.x active

根因分析

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

English

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

解决方案

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

无效尝试

常见但无效的做法:

  1. 80% 失败

    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% 失败

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