# Failed: 来自 pytest-timeout 的超时 (>60.0s)。

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

## 根因

测试或 fixture 阻塞时间超过配置的超时——常见原因是无超时的网络调用、未关闭的数据库连接，或线程 fixture 中的死锁。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   import httpx
r = httpx.get(url, timeout=5.0)

# or requests
requests.get(url, timeout=(3.05, 5))
   ```
2. **** (85% 成功率)
   ```
   # pytest.ini
[pytest]
timeout = 30
timeout_method = signal

# per test
@pytest.mark.timeout(10)
def test_fast(): ...
   ```

## 无效尝试

- **** — Masks the hang; CI still stalls and the underlying deadlock remains, eventually failing at a higher timeout. (75% 失败率)
- **** — Thread method can't interrupt blocking C calls (e.g., socket recv); the test still hangs and gets killed at signal level. (55% 失败率)
