# hypothesis.errors.DeadlineExceeded: 测试耗时 412.34ms，超过 200.00ms 的截止时间

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

## 根因

Hypothesis 对每个示例强制执行截止时间；慢速测试体、冷缓存或 CI 噪声会导致间歇性的 DeadlineExceeded 失败。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   from hypothesis import given, settings, strategies as st

@settings(deadline=1000)  # ms
@given(st.integers())
def test_parse(n):
    assert parse(n) == n
   ```
2. **** (85% 成功率)
   ```
   # Use hypothesis' --hypothesis-show-statistics and cProfile
pytest --hypothesis-show-statistics tests/test_x.py
# optimize hot paths in the code under test
   ```

## 无效尝试

- **** — Hides real performance regressions and makes flakiness reappear as timeouts elsewhere. (80% 失败率)
- **** — Warms caches but doesn't stop Hypothesis from measuring the slow example; may still exceed deadline. (70% 失败率)
- **** — Loses the value of property-based testing and may still hit the deadline on the first example. (85% 失败率)
