python
runtime_error
ai_generated
true
Failed: Timeout (>30.0s) from pytest-timeout. E Failed: Timeout (>30.0s) from pytest-timeout.
ID: python/pytest-timeout-fixture-hang
80%Fix Rate
84%Confidence
0Evidence
2024-11-19First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.x | active | — | — | — |
Root Cause
A fixture opens a resource (socket, subprocess, lock) and blocks indefinitely; pytest-timeout aborts the test but the fixture teardown never runs.
generic中文
fixture 打开资源(socket、子进程、锁)并无限阻塞;pytest-timeout 中止测试但 fixture 的 teardown 从未运行。
Workarounds
-
90% success
import socket @pytest.fixture def server(): s = socket.socket() s.settimeout(5) try: s.connect(('localhost', 8080)) except socket.timeout: pytest.skip('server not reachable') yield s s.close() -
85% success
pytest --timeout=30 --timeout-method=thread --timeout-func-only -q # Or set in pytest.ini: # [pytest] # timeout = 30 # timeout_method = thread
Dead Ends
Common approaches that don't work:
-
70% fail
The hang is real, not slow; increasing the timeout only delays the failure and wastes CI time.
-
90% fail
Removes the safety net; CI hangs forever.