# Failed: 超时 >30.0s

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

## 根因

pytest-timeout 中止超过配置超时的测试。常见原因：阻塞的网络调用、锁死锁、或未被 mock 的 sleep。

## 版本兼容性

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

## 解决方案

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

@patch('app.client.requests.get')
def test_fetch(mock_get):
    mock_get.return_value.json.return_value = {'ok': True}
    assert fetch()['ok'] is True
   ```
2. **** (85% 成功率)
   ```
   # pyproject.toml
[tool.pytest.ini_options]
timeout = 30
timeout_method = "thread"

# on failure a stack trace of the hung thread is printed
   ```

## 无效尝试

- **** — Masks the real issue; the underlying hang will still occur and slow CI. (75% 失败率)
- **** — Removes the safety net; a truly hung test blocks the whole run until the CI job times out. (80% 失败率)
