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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 98% 成功率
    # pyproject.toml
    [tool.pytest.ini_options]
    markers = [
      "slow: marks tests as slow (deselect with '-m \"not slow\"')",
      "integration: requires external services",
    ]
  2. 95% 成功率
    # pyproject.toml
    [tool.pytest.ini_options]
    addopts = "--strict-markers"
    markers = ["slow: slow tests"]

无效尝试

常见但无效的做法:

  1. 85% 失败

    Silences the warning but the mark remains unregistered; --strict-markers still errors and typo'd marks silently pass.

  2. 75% 失败

    Loses the ability to select/exclude the test via -m; CI's 'pytest -m "not slow"' no longer filters it.