# Failed: 来自 pytest-timeout 的超时（>30.0s）。

- **ID:** `python/pytest-timeout-test-hangs`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

测试在 I/O（网络、子进程、锁）上阻塞时间超过配置的超时。pytest-timeout 会终止测试，但底层挂起通常表明缺少 mock 或存在死锁。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.x | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Use the thread method to get a Python traceback at timeout:

pytest --timeout=30 --timeout-method=thread -s
   ```
2. **** (95% 成功率)
   ```
   Mock the blocking dependency (e.g. requests.get) or use a fake server; this usually reveals the missing mock.
   ```

## 无效尝试

- **** — Slows the suite and hides the real hang; CI eventually times out at the job level. (70% 失败率)
- **** — Hung tests block CI indefinitely, requiring manual cancellation. (90% 失败率)
