python config_error ai_generated true

pytest 使用错误:未知标记 'slow' - 也许你的意思是 'slow_test'?

pytest.PytestUsageError: Unknown marker 'slow' - maybe you meant 'slow_test'?

ID: python/pytest-marker-filter-error

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
0证据数
2026-01-18首次发现

版本兼容性

版本状态引入弃用备注
3.10 active

根因分析

测试使用了未在 pytest.ini 或 conftest.py 中注册的自定义标记(如 @pytest.mark.slow),导致 pytest 在过滤或运行带有该标记的测试时引发错误。

English

A test uses a custom marker (e.g., @pytest.mark.slow) that is not registered in pytest.ini or conftest.py, causing pytest to raise an error when filtering or running tests with that marker.

generic

解决方案

  1. 95% 成功率
    Register the marker in pytest.ini: [pytest] markers = slow: marks tests as slow, or in conftest.py: def pytest_configure(config): config.addinivalue_line('markers', 'slow: marks tests as slow')
  2. 70% 成功率
    Use the marker without filtering by running pytest with -k 'not slow' to skip unregistered markers, but registration is recommended.

无效尝试

常见但无效的做法:

  1. 50% 失败

    Ignoring the marker and running all tests without filtering may work but defeats the purpose of selective test execution.

  2. 60% 失败

    Using a similar built-in marker like @pytest.mark.skip may not achieve the desired filtering behavior.