python
config_error
ai_generated
true
PytestUnknownMarkWarning:未知的 pytest.mark.slowtest - 是拼写错误吗?你可以注册自定义标记以避免此警告
PytestUnknownMarkWarning: Unknown pytest.mark.slowtest - is this a typo? You can register custom marks to avoid this warning
ID: python/pytest-skip-marker-string
80%修复率
90%置信度
0证据数
2024-08-09首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
测试使用了未在 pytest.ini/pyproject.toml 中注册的自定义标记。Pytest 仍会应用该标记但发出警告,启用 strict-markers 后会变成错误。
English
The test uses a custom mark that is not registered in pytest.ini/pyproject.toml. Pytest still applies the mark but emits a warning, and with strict-markers enabled it becomes an error.
解决方案
-
98% 成功率
# pyproject.toml [tool.pytest.ini_options] markers = [ "slow: marks tests as slow (deselect with '-m \"not slow\"')", "integration: requires external services", ]
-
95% 成功率
# pyproject.toml [tool.pytest.ini_options] addopts = "--strict-markers" markers = ["slow: slow tests"]
无效尝试
常见但无效的做法:
-
85% 失败
Silences the warning but the mark remains unregistered; --strict-markers still errors and typo'd marks silently pass.
-
75% 失败
Loses the ability to select/exclude the test via -m; CI's 'pytest -m "not slow"' no longer filters it.