python
runtime_error
ai_generated
partial
失败: 超时 >300.0s pytest-timeout: test_heavy_import 在 300 秒后超时
Failed: Timeout >300.0s pytest-timeout: test_heavy_import timed out after 300 seconds
ID: python/pytest-timeout-test-exceeded
80%修复率
84%置信度
0证据数
2024-12-03首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
测试超过了配置的超时时间(全局或单测试)。通常由阻塞的网络调用、等待锁的未关闭数据库事务,或永不终止的子进程引起。
English
A test exceeded the configured timeout (global or per-test). Often caused by a blocking network call, an unclosed DB transaction waiting on a lock, or a subprocess that never terminates.
解决方案
-
90% 成功率
# pyproject.toml [tool.pytest.ini_options] addopts = "--timeout=60 --timeout-method=signal" # per-test @pytest.mark.timeout(10) def test_api(): ... -
85% 成功率
pytest -o faulthandler_timeout=30 tests/test_heavy_import.py -s # or run with py-spy py-spy dump --pid <pid>
无效尝试
常见但无效的做法:
-
70% 失败
Hides the real hang; CI now waits an hour per stuck test, and the underlying deadlock persists.
-
80% 失败
CI will hang indefinitely on the same test, blocking the whole pipeline.