python install_error ai_generated true

ERROR: 用法: pytest [options] [file_or_dir] [file_or_dir] [...] pytest: error: 无法识别的参数: --timeout=60 inifile: /app/pytest.ini rootdir: /app

ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...] pytest: error: unrecognized arguments: --timeout=60 inifile: /app/pytest.ini rootdir: /app

ID: python/pytest-timeout-plugin-missing

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

版本兼容性

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

根因分析

pytest.ini 中包含 `addopts = --timeout=60`,但未安装 pytest-timeout 插件,因此 pytest 拒绝该未知选项。

English

The pytest.ini contains `addopts = --timeout=60` but the pytest-timeout plugin is not installed, so pytest rejects the unknown option.

generic

解决方案

  1. 98% 成功率
    pip install pytest-timeout
    # then pytest.ini's addopts = --timeout=60 works
  2. 75% 成功率
    import signal
    import pytest
    
    @pytest.fixture
    def timeout():
        def handler(signum, frame):
            raise TimeoutError('test timed out')
        signal.signal(signal.SIGALRM, handler)
        signal.alarm(60)
        yield
        signal.alarm(0)

无效尝试

常见但无效的做法:

  1. 80% 失败

    Removes the timeout protection entirely; long-hanging tests can block CI indefinitely.

  2. 98% 失败

    Same unrecognized-argument error occurs because the plugin is still missing.