Skip to content

Commit b85bcdb

Browse files
committed
Mark expected failures under crosshair
1 parent eabcfcc commit b85bcdb

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

hypothesis-python/tests/common/utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# obtain one at https://mozilla.org/MPL/2.0/.
1010

1111
import contextlib
12+
import enum
1213
import sys
1314
from io import StringIO
1415
from types import SimpleNamespace
@@ -228,3 +229,32 @@ def temp_registered(type_, strat_or_factory):
228229
# config option, so *linking against* something built this way can break us.
229230
# Everything is terrible
230231
PYTHON_FTZ = next_down(sys.float_info.min) == 0.0
232+
233+
234+
class Why(enum.Enum):
235+
# Use an enum here so it's easier to find and/or exclude some cases later
236+
other = "other"
237+
flaky_replay = "Inconsistent results from replaying a failing test..."
238+
symbolic_outside_context = (
239+
"CrosshairInternal error from using value outside context"
240+
)
241+
undiscovered = "crosshair doesn't find the failing input"
242+
243+
244+
def xfail_on_crosshair(why: Why, /):
245+
import pytest
246+
try:
247+
import crosshair.util
248+
except ImportError:
249+
return pytest.mark.xf_crosshair
250+
251+
kw = {
252+
"strict": True,
253+
"reason": f"Expected failure due to: {why.value}",
254+
"condition": settings.get_profile(settings._current_profile).backend
255+
== "crosshair",
256+
}
257+
if why is Why.symbolic_outside_context:
258+
kw["raises"] = crosshair.util.CrosshairInternal
259+
260+
return lambda fn: pytest.mark.xf_crosshair(pytest.mark.xfail(**kw)(fn))

hypothesis-python/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def pytest_configure(config):
4646
"markers",
4747
"xp_min_version(api_version): run when greater or equal to api_version",
4848
)
49+
config.addinivalue_line("markers", "xf_crosshair: selection for xfailing symbolics")
4950

5051

5152
def pytest_addoption(parser):

hypothesis-python/tests/cover/test_testdecorators.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
)
3131

3232
from tests.common.utils import (
33+
Why,
3334
assert_falsifying_output,
3435
capture_out,
3536
fails,
3637
fails_with,
3738
no_shrink,
3839
raises,
3940
skipif_emscripten,
41+
xfail_on_crosshair,
4042
)
4143

4244
# This particular test file is run under both pytest and nose, so it can't
@@ -304,6 +306,7 @@ def test_has_ascii(x):
304306
assert any(c in ascii_characters for c in x)
305307

306308

309+
@xfail_on_crosshair(Why.symbolic_outside_context)
307310
def test_can_derandomize():
308311
values = []
309312

@@ -393,6 +396,7 @@ def test_mixed_text(x):
393396
assert set(x).issubset(set("abcdefg"))
394397

395398

399+
@xfail_on_crosshair(Why.other) # runs ~five failing examples
396400
def test_when_set_to_no_simplifies_runs_failing_example_twice():
397401
failing = []
398402

@@ -478,6 +482,7 @@ def test_empty_lists(xs):
478482
assert xs == []
479483

480484

485+
@xfail_on_crosshair(Why.other) # executes >> 2 tests, but there are only two bools
481486
def test_given_usable_inline_on_lambdas():
482487
xs = []
483488
given(booleans())(lambda x: xs.append(x))()

0 commit comments

Comments
 (0)