python config_error ai_generated true

PytestUnknownMarkWarning: 未知的 pytest.mark.smoke - 是否为拼写错误?

PytestUnknownMarkWarning: Unknown pytest.mark.smoke - is this a typo?

ID: python/pytest-marks-unknown-warning

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

版本兼容性

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

根因分析

使用了自定义标记如 @pytest.mark.smoke 但未在 pytest 配置中注册,因此 pytest 警告其未知。启用严格标记时这会变成错误。

English

A custom marker like @pytest.mark.smoke is used but not registered in pytest configuration, so pytest warns it is unknown. With strict markers enabled, this becomes an error.

generic

解决方案

  1. 95% 成功率
    Register markers in pytest.ini:
    
    [pytest]
    markers =
        smoke: quick smoke tests
        slow: long-running tests
  2. 93% 成功率
    Or in pyproject.toml:
    
    [tool.pytest.ini_options]
    markers = [
      'smoke: quick smoke tests',
    ]

无效尝试

常见但无效的做法:

  1. 85% 失败

    Suppressing the warning does not register the marker; `pytest -m smoke` still fails to select tests.

  2. 80% 失败

    This changes test semantics and does not provide the intended selection behavior.