Skip to content

Commit 9aaf6e4

Browse files
committed
prefer random= over deterministic_PRNG
1 parent 7fd52ba commit 9aaf6e4

File tree

10 files changed

+580
-648
lines changed

10 files changed

+580
-648
lines changed

hypothesis-python/tests/common/utils.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from hypothesis import Phase, settings
2222
from hypothesis.errors import HypothesisDeprecationWarning
2323
from hypothesis.internal import observability
24-
from hypothesis.internal.entropy import deterministic_PRNG
2524
from hypothesis.internal.floats import next_down
2625
from hypothesis.internal.observability import (
2726
Observation,
@@ -127,11 +126,7 @@ def fails_with(e, *, match=None):
127126
def accepts(f):
128127
@proxies(f)
129128
def inverted_test(*arguments, **kwargs):
130-
# Most of these expected-failure tests are non-deterministic, so
131-
# we rig the PRNG to avoid occasional flakiness. We do this outside
132-
# the `raises` context manager so that any problems in rigging the
133-
# PRNG don't accidentally count as the expected failure.
134-
with deterministic_PRNG(), raises(e, match=match):
129+
with raises(e, match=match):
135130
f(*arguments, **kwargs)
136131

137132
return inverted_test

hypothesis-python/tests/conjecture/common.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
)
2828
from hypothesis.internal.conjecture.providers import COLLECTION_DEFAULT_MAX_SIZE
2929
from hypothesis.internal.conjecture.utils import calc_label_from_name
30-
from hypothesis.internal.entropy import deterministic_PRNG
3130
from hypothesis.internal.escalation import InterestingOrigin
3231
from hypothesis.internal.floats import SMALLEST_SUBNORMAL
3332
from hypothesis.internal.intervalsets import IntervalSet
@@ -52,17 +51,17 @@ def interesting_origin(n: int | None = None) -> InterestingOrigin:
5251

5352

5453
def run_to_data(f):
55-
with deterministic_PRNG():
56-
runner = ConjectureRunner(
57-
f,
58-
settings=settings(
59-
max_examples=300, database=None, suppress_health_check=list(HealthCheck)
60-
),
61-
)
62-
runner.run()
63-
assert runner.interesting_examples
64-
(last_data,) = runner.interesting_examples.values()
65-
return last_data
54+
runner = ConjectureRunner(
55+
f,
56+
settings=settings(
57+
max_examples=300, database=None, suppress_health_check=list(HealthCheck)
58+
),
59+
random=Random(0),
60+
)
61+
runner.run()
62+
assert runner.interesting_examples
63+
(last_data,) = runner.interesting_examples.values()
64+
return last_data
6665

6766

6867
def run_to_nodes(f):
@@ -85,24 +84,23 @@ def buffer_size_limit(n):
8584

8685
def shrinking_from(start):
8786
def accept(f):
88-
with deterministic_PRNG():
89-
runner = ConjectureRunner(
90-
f,
91-
settings=settings(
92-
max_examples=5000,
93-
database=None,
94-
suppress_health_check=list(HealthCheck),
95-
# avoid running the explain phase in shrinker.shrink() in tests
96-
# which don't test the inquisitor.
97-
phases=set(settings.default.phases) - {Phase.explain},
98-
),
99-
)
100-
runner.cached_test_function(start)
101-
assert runner.interesting_examples
102-
(last_data,) = runner.interesting_examples.values()
103-
return runner.new_shrinker(
104-
last_data, lambda d: d.status == Status.INTERESTING
105-
)
87+
runner = ConjectureRunner(
88+
f,
89+
settings=settings(
90+
max_examples=5000,
91+
database=None,
92+
suppress_health_check=list(HealthCheck),
93+
# avoid running the explain phase in shrinker.shrink() in tests
94+
# which don't test the inquisitor.
95+
phases=set(settings.default.phases) - {Phase.explain},
96+
),
97+
random=Random(0),
98+
)
99+
runner.cached_test_function(start)
100+
assert runner.interesting_examples
101+
102+
(last_data,) = runner.interesting_examples.values()
103+
return runner.new_shrinker(last_data, lambda d: d.status == Status.INTERESTING)
106104

107105
return accept
108106

0 commit comments

Comments
 (0)