python runtime_error ai_generated true

Failed: 来自 pytest-timeout 的超时 (>60.0s)。

Failed: Timeout (>60.0s) from pytest-timeout.

ID: python/pytest-timeout-exceeded-hanging-test

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

版本兼容性

版本状态引入弃用备注
2.2.x active — — —
2.3.x active — — —

根因分析

测试或 fixture 阻塞时间超过配置的超时——常见原因是无超时的网络调用、未关闭的数据库连接,或线程 fixture 中的死锁。

English

A test or fixture blocked longer than the configured timeout — often due to a network call without timeout, an unclosed DB connection, or a deadlock in a threaded fixture.

generic

解决方案

  1. 90% 成功率
    import httpx
    r = httpx.get(url, timeout=5.0)
    
    # or requests
    requests.get(url, timeout=(3.05, 5))
  2. 85% 成功率
    # pytest.ini
    [pytest]
    timeout = 30
    timeout_method = signal
    
    # per test
    @pytest.mark.timeout(10)
    def test_fast(): ...

无效尝试

常见但无效的做法:

  1. 75% 失败

    Masks the hang; CI still stalls and the underlying deadlock remains, eventually failing at a higher timeout.

  2. 55% 失败

    Thread method can't interrupt blocking C calls (e.g., socket recv); the test still hangs and gets killed at signal level.