python config_error ai_generated true

Failed: Skipped: you need to specify a reason the pytest.mark.skipif is skipping ERROR: found no collectors for tests/test_x.py::test_y

ID: python/pytest-skipif-string-condition

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

Version Compatibility

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

Root Cause

pytest.mark.skipif requires both a condition and a reason keyword. Passing a string as the first positional arg (a common mistake) makes pytest treat it as an invalid condition.

generic

中文

pytest.mark.skipif 需要同时提供条件和 reason 关键字。将字符串作为第一个位置参数传入(常见错误)会让 pytest 视为无效条件。

Workarounds

  1. 98% success
    Use keyword arguments:
      @pytest.mark.skipif(sys.platform == 'win32', reason='POSIX-only')
      def test_x(): ...
  2. 95% success
    For module-level skips:
      pytestmark = pytest.mark.skipif(condition, reason='...')

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Unconditionally skips the test even on platforms where it should run.

  2. 80% fail

    Positional args are not supported for reason; must be keyword.