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
80%Fix Rate
90%Confidence
0Evidence
2024-03-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 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
-
98% success
Use keyword arguments: @pytest.mark.skipif(sys.platform == 'win32', reason='POSIX-only') def test_x(): ...
-
95% success
For module-level skips: pytestmark = pytest.mark.skipif(condition, reason='...')
Dead Ends
Common approaches that don't work:
-
90% fail
Unconditionally skips the test even on platforms where it should run.
-
80% fail
Positional args are not supported for reason; must be keyword.