1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
# This file is part of Hypothesis, which may be found at
# https://github.com/HypothesisWorks/hypothesis/
#
# Copyright the Hypothesis Authors.
# Individual contributors are listed in AUTHORS.rst and the git log.
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/.
from random import Random
import pytest
from hypothesis import (
HealthCheck,
Verbosity,
core,
given,
settings,
strategies as st,
)
from tests.common.utils import Why, no_shrink, xfail_on_crosshair
@pytest.mark.skipif(
settings._current_profile == "crosshair",
reason="we do not yet pass backends the global random seed, so they are not deterministic",
)
def test_seeds_off_internal_random():
choices1 = []
choices2 = []
@given(st.integers())
def f1(n):
choices1.append(n)
@given(st.integers())
def f2(n):
choices2.append(n)
core.threadlocal._hypothesis_global_random = Random(0)
state = core.threadlocal._hypothesis_global_random.getstate()
f1()
core.threadlocal._hypothesis_global_random.setstate(state)
f2()
assert choices1 == choices2
@xfail_on_crosshair(Why.nested_given)
def test_nesting_with_control_passes_health_check():
@given(st.integers(0, 100), st.random_module())
@settings(
max_examples=5,
database=None,
deadline=None,
suppress_health_check=[HealthCheck.nested_given],
)
def test_blah(x, rnd):
@given(st.integers())
@settings(
max_examples=100, phases=no_shrink, database=None, verbosity=Verbosity.quiet
)
def test_nest(y):
assert y < x
with pytest.raises(AssertionError):
test_nest()
test_blah()
|