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

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

## 根因

测试阻塞超过配置的超时时间，通常由网络调用、死锁或未关闭的资源等待输入引起。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   from unittest import mock

def test_fetch(monkeypatch):
    monkeypatch.setattr('myapp.client.requests.get', lambda *a, **k: FakeResp())
    assert myapp.client.fetch()
   ```
2. **** (85% 成功率)
   ```
   # pytest.ini
[pytest]
timeout = 60
timeout_method = signal
# on failure, pytest prints the stack where the test hung
   ```

## 无效尝试

- **** — Hides the underlying hang; CI duration balloons and the real bug (deadlock, missing mock) persists. (85% 失败率)
- **** — Test suite hangs indefinitely in CI, blocking the whole pipeline until the job-level timeout. (95% 失败率)
- **** — Loses coverage and leaves the bug in production code undetected. (90% 失败率)
