python
config_error
ai_generated
true
PytestDeprecationWarning: 不带 reason 的 pytest.mark.skip 已弃用 @pytest.mark.skip 在 pytest 7.0 中弃用,未来版本将报错
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
80%修复率
87%置信度
0证据数
2024-02-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
现代 pytest 中 `@pytest.mark.skip` 和 `@pytest.mark.skipif` 需要 `reason=` 关键字;省略会触发弃用警告,在 `-W error` 下变成错误。
English
`@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`.
解决方案
-
97% 成功率
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(): ...
-
90% 成功率
Or use `pytest.importorskip` for optional deps: np = pytest.importorskip('numpy', reason='numpy not installed')
无效尝试
常见但无效的做法:
-
80% 失败
Suppresses all deprecations, hiding real issues across the suite.
-
75% 失败
Changes semantics: xfail expects failure, skip does not run; tests may start passing and turn XPASS.