python runtime_error ai_generated true

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

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

ID: python/pytest-timeout-hung-test

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

版本兼容性

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

根因分析

测试阻塞在网络 I/O、未关闭的套接字、死锁或无限循环上;pytest-timeout 在配置的阈值后终止了它。

English

A test blocked on network I/O, an unclosed socket, a deadlock, or an infinite loop; pytest-timeout killed it after the configured threshold.

generic

解决方案

  1. 90% 成功率
    pytest --timeout=60 --timeout-method=thread -o faulthandler_timeout=55 tests/test_net.py
  2. 95% 成功率
    from unittest import mock
    
    @mock.patch('app.client.requests.get')
    def test_fetch(mock_get):
        mock_get.return_value.json.return_value = {"ok": True}
        ...
  3. 88% 成功率
    @pytest.mark.timeout(5)
    def test_quick(): ...

无效尝试

常见但无效的做法:

  1. 85% 失败

    Extends CI time without fixing the underlying hang.

  2. 95% 失败

    CI hangs indefinitely; hides the bug.

  3. 90% 失败

    A hang is not flakiness.