python system_error ai_generated partial

Failed: Timeout >30.0s

ID: python/pytest-timeout-failed

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-08-27First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.x active — — —
8.x active — — —

Root Cause

pytest-timeout aborts a test that exceeds its configured timeout. Often caused by a blocking network call, a deadlock on a lock, or a sleep not being mocked.

generic

中文

pytest-timeout 中止超过配置超时的测试。常见原因:阻塞的网络调用、锁死锁、或未被 mock 的 sleep。

Workarounds

  1. 92% success
    from unittest.mock import patch
    
    @patch('app.client.requests.get')
    def test_fetch(mock_get):
        mock_get.return_value.json.return_value = {'ok': True}
        assert fetch()['ok'] is True
  2. 85% success
    # pyproject.toml
    [tool.pytest.ini_options]
    timeout = 30
    timeout_method = "thread"
    
    # on failure a stack trace of the hung thread is printed

Dead Ends

Common approaches that don't work:

  1. 75% fail

    Masks the real issue; the underlying hang will still occur and slow CI.

  2. 80% fail

    Removes the safety net; a truly hung test blocks the whole run until the CI job times out.