Skip to content

Commit 2b50425

Browse files
committed
Skip crosshair-incompatible tests
1 parent 77e3d4a commit 2b50425

File tree

5 files changed

+59
-15
lines changed

5 files changed

+59
-15
lines changed

hypothesis-python/tests/conjecture/common.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
from random import Random
1515
from typing import Optional
1616

17+
import pytest
18+
1719
from hypothesis import HealthCheck, Phase, assume, settings, strategies as st
18-
from hypothesis.control import current_build_context
19-
from hypothesis.errors import InvalidArgument
20+
from hypothesis.control import current_build_context, currently_in_test_context
2021
from hypothesis.internal.conjecture import engine as engine_module
2122
from hypothesis.internal.conjecture.choice import ChoiceNode, ChoiceT
2223
from hypothesis.internal.conjecture.data import ConjectureData, Status
@@ -103,10 +104,21 @@ def accept(f):
103104

104105

105106
def fresh_data(*, random=None, observer=None) -> ConjectureData:
107+
context = current_build_context() if currently_in_test_context() else None
108+
if context is not None and settings().backend == "crosshair":
109+
# we should reeaxmine fresh_data sometime and see if we can replace it
110+
# with nicer and higher level hypothesis idioms.
111+
#
112+
# For now it doesn't work well with crosshair tests. This is no big
113+
# loss, because these tests often rely on hypothesis-provider-specific
114+
# things.
115+
pytest.skip(
116+
"Fresh data is too low level (and too much of a hack) to be "
117+
"worth supporting when testing with crosshair"
118+
)
119+
106120
if random is None:
107-
try:
108-
context = current_build_context()
109-
except InvalidArgument:
121+
if context is None:
110122
# ensure usage of fresh_data() is not flaky outside of property tests.
111123
raise ValueError(
112124
"must pass a seeded Random instance to fresh_data() when "

hypothesis-python/tests/nocover/test_database_agreement.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import shutil
1313
import tempfile
1414

15-
from hypothesis import strategies as st
15+
import pytest
16+
17+
from hypothesis import settings, strategies as st
1618
from hypothesis.database import (
1719
BackgroundWriteDatabase,
1820
DirectoryBasedExampleDatabase,
@@ -28,7 +30,6 @@ def __init__(self):
2830
exampledir = os.path.join(self.tempd, "examples")
2931

3032
self.dbs = [
31-
DirectoryBasedExampleDatabase(exampledir),
3233
InMemoryExampleDatabase(),
3334
DirectoryBasedExampleDatabase(exampledir),
3435
BackgroundWriteDatabase(InMemoryExampleDatabase()),
@@ -75,4 +76,6 @@ def teardown(self):
7576
shutil.rmtree(self.tempd)
7677

7778

78-
TestDBs = DatabaseComparison.TestCase
79+
@pytest.mark.skipif(settings._current_profile == "crosshair", reason="isn't threadsafe")
80+
def test_database_equivalence():
81+
DatabaseComparison.TestCase().runTest()

hypothesis-python/tests/nocover/test_precise_shrinking.py

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959

6060
T = TypeVar("T")
6161

62+
pytestmark = pytest.mark.skipif(
63+
settings._current_profile == "crosshair",
64+
reason="using internals for testing in a way crosshair doesn't support",
65+
)
66+
6267

6368
def safe_draw(data, strategy):
6469
"""Set up just enough of the Hypothesis machinery to use draw on

hypothesis-python/tests/nocover/test_randomization.py

+25-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
99
# obtain one at https://mozilla.org/MPL/2.0/.
1010

11+
from random import Random
12+
1113
import pytest
1214

1315
from hypothesis import (
1416
HealthCheck,
1517
Verbosity,
1618
core,
17-
find,
1819
given,
1920
settings,
2021
strategies as st,
@@ -23,13 +24,30 @@
2324
from tests.common.utils import Why, no_shrink, xfail_on_crosshair
2425

2526

27+
@pytest.mark.skipif(
28+
settings._current_profile == "crosshair",
29+
reason="we do not yet pass backends the global random seed, so they are not deterministic",
30+
)
2631
def test_seeds_off_internal_random():
27-
s = settings(phases=no_shrink, database=None)
28-
r = core._hypothesis_global_random.getstate()
29-
x = find(st.integers(), lambda x: True, settings=s)
30-
core._hypothesis_global_random.setstate(r)
31-
y = find(st.integers(), lambda x: True, settings=s)
32-
assert x == y
32+
choices1 = []
33+
choices2 = []
34+
35+
@given(st.integers())
36+
def f1(n):
37+
choices1.append(n)
38+
39+
@given(st.integers())
40+
def f2(n):
41+
choices2.append(n)
42+
43+
core._hypothesis_global_random = Random(0)
44+
state = core._hypothesis_global_random.getstate()
45+
f1()
46+
47+
core._hypothesis_global_random.setstate(state)
48+
f2()
49+
50+
assert choices1 == choices2
3351

3452

3553
@xfail_on_crosshair(Why.nested_given)

hypothesis-python/tests/nocover/test_stateful.py

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
run_state_machine_as_test,
2424
)
2525

26+
from tests.common.utils import Why
27+
2628

2729
def run_to_notes(TestClass):
2830
TestCase = TestClass.TestCase
@@ -204,6 +206,10 @@ def snake(self):
204206
"machine", bad_machines, ids=[t.__name__ for t in bad_machines]
205207
)
206208
def test_bad_machines_fail(machine):
209+
if machine is CanSwarm and Settings._current_profile == "crosshair":
210+
# and also takes 10 minutes, on top of not finding the failure
211+
pytest.xfail(reason=str(Why.undiscovered))
212+
207213
test_class = machine.TestCase
208214
try:
209215
test_class().runTest()

0 commit comments

Comments
 (0)