Skip to content

Commit b648264

Browse files
committed
Improve too_slow healthcheck
1 parent c10559a commit b648264

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RELEASE_TYPE: patch
2+
3+
This patch makes the :obj:`~hypothesis.HealthCheck.too_slow` health check more
4+
consistent with long :obj:`~hypothesis.settings.deadline` tests (:issue:`3367`)

hypothesis-python/src/hypothesis/internal/conjecture/engine.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import time
1414
from collections import defaultdict
1515
from contextlib import contextmanager
16+
from datetime import timedelta
1617
from enum import Enum
1718
from random import Random, getrandbits
1819
from weakref import WeakKeyDictionary
@@ -386,7 +387,10 @@ def record_for_health_check(self, data):
386387

387388
draw_time = sum(state.draw_times)
388389

389-
if draw_time > 1.0:
390+
# Allow at least the greater of one second or 5x the deadline. If deadline
391+
# is None, allow 30s - the user can disable the healthcheck too if desired.
392+
draw_time_limit = 5 * (self.settings.deadline or timedelta(seconds=6))
393+
if draw_time > max(1.0, draw_time_limit.total_seconds()):
390394
fail_health_check(
391395
self.settings,
392396
"Data generation is extremely slow: Only produced "

hypothesis-python/tests/cover/test_health_checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test(x):
4545

4646

4747
def test_slow_generation_inline_fails_a_health_check():
48-
@settings(HEALTH_CHECK_SETTINGS, deadline=None)
48+
@HEALTH_CHECK_SETTINGS
4949
@given(st.data())
5050
def test(data):
5151
data.draw(st.integers().map(lambda x: time.sleep(0.2)))

0 commit comments

Comments
 (0)