python config_error ai_generated true

PytestDeprecationWarning: pytest.mark.skip without reason is deprecated @pytest.mark.skip deprecated in pytest 7.0, will be an error in future versions

ID: python/pytest-skip-marker-missing-reason

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.x active — — —
8.x active — — —

Root Cause

`@pytest.mark.skip` and `@pytest.mark.skipif` require a `reason=` keyword in modern pytest; omitting it triggers a deprecation warning that becomes an error under `-W error`.

generic

中文

现代 pytest 中 `@pytest.mark.skip` 和 `@pytest.mark.skipif` 需要 `reason=` 关键字;省略会触发弃用警告,在 `-W error` 下变成错误。

Workarounds

  1. 97% success
    Always pass a reason:
    @pytest.mark.skip(reason='requires GPU')
    def test_cuda(): ...
    
    @pytest.mark.skipif(sys.platform == 'win32', reason='POSIX only')
    def test_fork(): ...
  2. 90% success
    Or use `pytest.importorskip` for optional deps:
    np = pytest.importorskip('numpy', reason='numpy not installed')

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Suppresses all deprecations, hiding real issues across the suite.

  2. 75% fail

    Changes semantics: xfail expects failure, skip does not run; tests may start passing and turn XPASS.