Skip to content

Commit 5cc3818

Browse files
authored
Merge pull request #3376 from Zac-HD/tune-healthcheck
Fix pipenv install issue and sometimes-too-short draw time healthcheck
2 parents b73d6fd + 9632a90 commit 5cc3818

File tree

8 files changed

+31
-19
lines changed

8 files changed

+31
-19
lines changed

hypothesis-python/RELEASE.rst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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`)
5+
and fixes an install issue under :pypi:`pipenv` which was introduced in
6+
:ref:`Hypothesis 6.47.2 <v6.47.2>` (:issue:`3374`).

hypothesis-python/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def local_file(name):
102102
extras_require=extras,
103103
install_requires=[
104104
"attrs>=19.2.0",
105-
"exceptiongroup>=1.0.0rc8 ; python_version<'3.11.0b1'",
105+
"exceptiongroup>=1.0.0rc8 ; python_version<'3.11'",
106106
"sortedcontainers>=2.1.0,<3.0.0",
107107
],
108108
python_requires=">=3.7",

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

+5-1
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/common/utils.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import contextlib
1212
import sys
1313
from io import StringIO
14+
from types import SimpleNamespace
1415

1516
from hypothesis import Phase, settings
1617
from hypothesis.errors import HypothesisDeprecationWarning
@@ -29,9 +30,11 @@
2930

3031
@contextlib.contextmanager
3132
def raises(expected_exception, match=None):
33+
err = SimpleNamespace(value=None)
3234
try:
33-
yield
35+
yield err
3436
except expected_exception as e:
37+
err.value = e
3538
if match is not None:
3639
import re
3740

@@ -175,11 +178,14 @@ def assert_falsifying_output(
175178
if expected_exception is None:
176179
# Some tests want to check the output of non-failing runs.
177180
test()
181+
msg = ""
178182
else:
179-
with raises(expected_exception):
183+
with raises(expected_exception) as exc_info:
180184
test()
185+
notes = "\n".join(getattr(exc_info.value, "__notes__", []))
186+
msg = str(exc_info.value) + "\n" + notes
181187

182-
output = out.getvalue()
188+
output = out.getvalue() + msg
183189
assert f"{example_type} example:" in output
184190
assert_output_contains_failure(output, test, **kwargs)
185191

hypothesis-python/tests/cover/test_control.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_does_not_suppress_exceptions():
7474

7575

7676
def test_suppresses_exceptions_in_teardown():
77-
with pytest.raises(ValueError) as err:
77+
with pytest.raises(ValueError) as exc_info:
7878
with bc():
7979

8080
def foo():
@@ -83,12 +83,12 @@ def foo():
8383
cleanup(foo)
8484
raise AssertionError
8585

86-
assert isinstance(err.value, ValueError)
87-
assert isinstance(err.value.__cause__, AssertionError)
86+
assert isinstance(exc_info.value, ValueError)
87+
assert isinstance(exc_info.value.__cause__, AssertionError)
8888

8989

9090
def test_runs_multiple_cleanup_with_teardown():
91-
with pytest.raises(ExceptionGroup) as err:
91+
with pytest.raises(ExceptionGroup) as exc_info:
9292
with bc():
9393

9494
def foo():
@@ -101,9 +101,9 @@ def bar():
101101
cleanup(bar)
102102
raise AssertionError
103103

104-
assert isinstance(err.value, ExceptionGroup)
105-
assert isinstance(err.value.__cause__, AssertionError)
106-
assert {type(e) for e in err.value.exceptions} == {ValueError, TypeError}
104+
assert isinstance(exc_info.value, ExceptionGroup)
105+
assert isinstance(exc_info.value.__cause__, AssertionError)
106+
assert {type(e) for e in exc_info.value.exceptions} == {ValueError, TypeError}
107107
assert _current_build_context.value is None
108108

109109

hypothesis-python/tests/cover/test_health_checks.py

+1-1
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)))

hypothesis-python/tests/nocover/test_interesting_origin.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,5 @@ def test_fn(x, y):
5858
# Indirection to fix https://github.com/HypothesisWorks/hypothesis/issues/2888
5959
return function(x, y)
6060

61-
try:
61+
with pytest.raises(MultipleFailures):
6262
test_fn()
63-
except MultipleFailures:
64-
pass
65-
else:
66-
raise AssertionError("Expected MultipleFailures")

hypothesis-python/tests/nocover/test_targeting.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_threshold_problem(x):
2929
@pytest.mark.parametrize("multiple", [False, True])
3030
def test_reports_target_results(testdir, multiple):
3131
script = testdir.makepyfile(TESTSUITE.format("" if multiple else "# "))
32-
result = testdir.runpytest(script)
32+
result = testdir.runpytest(script, "--tb=native")
3333
out = "\n".join(result.stdout.lines)
3434
assert "Falsifying example" in out
3535
assert "x=101" in out

0 commit comments

Comments
 (0)