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-mark-unknown-warning

其他格式: JSON · Markdown 中文 · English
80%修复率
90%置信度
0证据数
2024-02-27首次发现

版本兼容性

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

根因分析

使用了自定义标记(例如 @pytest.mark.slow)但未注册,因此 pytest 发出警告,并且 -m 'slow' 过滤可能无法按预期工作。

English

A custom marker (e.g., @pytest.mark.slow) is used but not registered, so pytest emits a warning and -m 'slow' filtering may not behave as expected.

generic

解决方案

  1. 98% 成功率
    # pytest.ini
    [pytest]
    markers =
        slow: marks tests as slow
        integration: requires external services
  2. 95% 成功率
    # pyproject.toml
    [tool.pytest.ini_options]
    markers = [
      "slow: marks tests as slow",
      "integration: requires external services",
    ]

无效尝试

常见但无效的做法:

  1. 80% 失败

    Silences the warning but -m filtering still doesn't recognize the mark.

  2. 70% 失败

    -k matches names, not markers; results differ.

  3. 30% 失败

    Works but duplicates config; pytest.ini is simpler and canonical.