Skip to content

Commit

Permalink
reword, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tybug committed Dec 8, 2024
1 parent 7c11f95 commit 5903fe9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
4 changes: 2 additions & 2 deletions hypothesis-python/src/hypothesis/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1250,8 +1250,8 @@ def run_engine(self):
if runner.overrun_examples > min(20, runner.call_count // 5):
explanations.append(
f"{runner.overrun_examples} of {runner.call_count} "
"examples were too large to finish generating. Try "
"reducing the size of your inputs."
"examples were too large to finish generating; try "
"reducing the typical size of your inputs?"
)
rep = get_pretty_function_description(self.test)
raise Unsatisfiable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ def text(
f"st.text({alphabet!r}): it seems like you are trying to use the "
f"codec {alphabet!r}. st.text({alphabet!r}) instead generates "
f"strings using the literal characters {list(alphabet)!r}. To specify "
f"the {alphabet} codec, use st.text(st.characters({alphabet!r})). "
f"the {alphabet} codec, use st.text(st.characters(codec={alphabet!r})). "
"If you intended to use character literals, you can silence this "
"warning by reordering the characters.",
HypothesisWarning,
Expand Down
50 changes: 49 additions & 1 deletion hypothesis-python/tests/cover/test_testdecorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@
import threading
from collections import namedtuple

from hypothesis import HealthCheck, Verbosity, assume, given, note, reporting, settings
from hypothesis import (
HealthCheck,
Verbosity,
assume,
given,
note,
reporting,
settings,
strategies as st,
)
from hypothesis.errors import Unsatisfiable
from hypothesis.strategies import (
binary,
booleans,
Expand Down Expand Up @@ -484,3 +494,41 @@ def test_given_usable_inline_on_lambdas():
given(booleans())(lambda x: xs.append(x))()
assert len(xs) == 2
assert set(xs) == {False, True}


def test_notes_high_filter_rates_in_unsatisfiable_error():
@given(st.integers())
@settings(suppress_health_check=[HealthCheck.filter_too_much])
def f(v):
assume(False)

with raises(
Unsatisfiable,
match=(
r"Unable to satisfy assumptions of f\. 1000 of 1000 examples "
r"failed a \.filter\(\) or assume\(\)"
),
):
f()


def test_notes_high_overrun_rates_in_unsatisfiable_error():
@given(st.binary(min_size=9000))
@settings(
suppress_health_check=[
HealthCheck.data_too_large,
HealthCheck.too_slow,
HealthCheck.large_base_example,
]
)
def f(v):
pass

with raises(
Unsatisfiable,
match=(
r"1000 of 1000 examples were too large to finish generating; "
r"try reducing the typical size of your inputs\?"
),
):
f()

0 comments on commit 5903fe9

Please sign in to comment.