python config_error ai_generated true

PytestUnknownMarkWarning: 未知的 pytest.mark.slow - 是否拼写错误?你可以注册自定义标记以避免此警告

PytestUnknownMarkWarning: Unknown pytest.mark.slow - is this a typo? You can register custom marks to avoid this warning

ID: python/pytest-marker-unknown-warning

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
0证据数
2025-07-08首次发现

版本兼容性

版本状态引入弃用备注
7.x active
8.x active

根因分析

使用了未在 pytest.ini/pyproject.toml 注册的自定义标记;pytest 发出警告,在 `-W error` 下变为失败。

English

A custom marker is used without being registered in pytest.ini/pyproject.toml; pytest emits a warning, and with `-W error` it becomes a failure.

generic

解决方案

  1. 98% 成功率
    # pyproject.toml
    [tool.pytest.ini_options]
    markers = [
      "slow: marks tests as slow",
      "integration: requires external services",
    ]
    
    # then
    pytest -m slow
  2. 90% 成功率
    # pyproject.toml
    [tool.pytest.ini_options]
    addopts = "--strict-markers"
    markers = ["slow: slow tests"]

无效尝试

常见但无效的做法:

  1. 90% 失败

    Changes test semantics (skips instead of conditionally selecting) and loses filtering capability.

  2. 70% 失败

    Hides typos in marker names and prevents `--strict-markers` from catching regressions.

  3. 95% 失败

    Suppresses all warnings, including real deprecations and correctness issues.