Skip to content

Speed up slow tests, increase db listener test retries #4456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hypothesis-python/tests/cover/test_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,7 @@ def test_resolves_builtin_types(t):

@pytest.mark.parametrize("t", BUILTIN_TYPES, ids=lambda t: t.__name__)
@given(data=st.data())
@settings(max_examples=20)
def test_resolves_forwardrefs_to_builtin_types(t, data):
s = st.from_type(typing.ForwardRef(t.__name__))
v = data.draw(s)
Expand Down
3 changes: 2 additions & 1 deletion hypothesis-python/tests/nocover/test_characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def _enc(cdc):
reason="takes 2000s; large & slow symbolic strings",
)
@given(data=st.data(), codec=st.sampled_from(lots_of_encodings))
@settings(max_examples=20)
def test_can_constrain_characters_to_codec(data, codec):
s = data.draw(st.text(st.characters(codec=codec), min_size=100))
s = data.draw(st.text(st.characters(codec=codec), min_size=50))
s.encode(codec)
33 changes: 17 additions & 16 deletions hypothesis-python/tests/nocover/test_health_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import pytest
from pytest import raises

from hypothesis import HealthCheck, Phase, given, settings, strategies as st
from hypothesis import HealthCheck, Phase, given, seed, settings, strategies as st
from hypothesis.errors import FailedHealthCheck
from hypothesis.internal.conjecture.data import ConjectureData
from hypothesis.internal.conjecture.engine import BUFFER_SIZE
Expand Down Expand Up @@ -107,21 +107,22 @@ def test(n):
test()


def test_does_not_trigger_health_check_when_most_examples_are_small(monkeypatch):
with deterministic_PRNG():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about nondeterministic failures here; maybe we can apply @seed(idx) instead with the loop variable?

Copy link
Member Author

@tybug tybug Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

I don't care too much about nondeterministic failures honestly, I'd actually prefer to use less seeding in our tests in general, so that we don't get silently passing seeded tests when they would have caught a real failure eventually. Of course the flipside is dealing with flakes.

for _ in range(100):
# Setting max_examples=11 ensures we have enough examples for the
# health checks to finish running, but cuts the generation short
# after that point to allow this test to run in reasonable time.
@settings(database=None, max_examples=11, phases=[Phase.generate])
@given(
st.integers(0, 100).flatmap(
lambda n: st.binary(
min_size=min(n * 100, BUFFER_SIZE), max_size=n * 100
)
def test_does_not_trigger_health_check_when_most_examples_are_small():
for i in range(10):

@seed(i)
# Setting max_examples=11 ensures we have enough examples for the
# health checks to finish running, but cuts the generation short
# after that point to allow this test to run in reasonable time.
@settings(database=None, max_examples=11, phases=[Phase.generate])
@given(
st.integers(0, 100).flatmap(
lambda n: st.binary(
min_size=min(n * 100, BUFFER_SIZE), max_size=n * 100
)
)
def test(b):
pass
)
def test(b):
pass

test()
test()
6 changes: 3 additions & 3 deletions hypothesis-python/tests/watchdog/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_database_listener_directory():
# seen flaky on test-win; we get *three* of the same save events in the first
# assertion, which...is baffling, and possibly a genuine bug (most likely in
# watchdog).
@flaky(max_runs=2, min_passes=1)
@flaky(max_runs=5, min_passes=1)
def test_database_listener_multiplexed(tmp_path):
db = MultiplexedDatabase(
InMemoryExampleDatabase(), DirectoryBasedExampleDatabase(tmp_path)
Expand Down Expand Up @@ -96,7 +96,7 @@ def wait_for(condition, *, timeout=1, interval=0.01):


# seen flaky on check-coverage (timeout in first wait_for)
@flaky(max_runs=2, min_passes=1)
@flaky(max_runs=5, min_passes=1)
def test_database_listener_directory_explicit(tmp_path):
db = DirectoryBasedExampleDatabase(tmp_path)
events = []
Expand Down Expand Up @@ -167,7 +167,7 @@ def listener(event):


# seen flaky on windows CI (timeout in wait_for)
@flaky(max_runs=2, min_passes=1)
@flaky(max_runs=5, min_passes=1)
def test_database_listener_directory_move(tmp_path):
db = DirectoryBasedExampleDatabase(tmp_path)
events = []
Expand Down