python runtime_error ai_generated true

hypothesis.errors.DeadlineExceeded: Test took 412.34ms, which exceeds the deadline of 200.00ms

ID: python/pytest-hypothesis-deadline-exceeded

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2025-08-02First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
6.x active

Root Cause

Hypothesis enforces a per-example deadline; slow test bodies, cold caches, or CI noise cause intermittent DeadlineExceeded failures.

generic

中文

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

Workarounds

  1. 90% success
    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% success
    # Use hypothesis' --hypothesis-show-statistics and cProfile
    pytest --hypothesis-show-statistics tests/test_x.py
    # optimize hot paths in the code under test

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Hides real performance regressions and makes flakiness reappear as timeouts elsewhere.

  2. 70% fail

    Warms caches but doesn't stop Hypothesis from measuring the slow example; may still exceed deadline.

  3. 85% fail

    Loses the value of property-based testing and may still hit the deadline on the first example.