test_assume_has_status_reason fails under the crosshair backend because of a CPython sys.monitoring bug
tests/cover/test_observability.py::test_assume_has_status_reason fails consistently with HYPOTHESIS_PROFILE=crosshair on Python 3.13 (crosshair-tool 0.0.110, hypothesis-crosshair 0.0.30, Hypothesis master at 6cee8ce). It has failed every time since the test was added in 85b860c:
AssertionError: assert False
+ where False = <built-in method startswith of str object>('failed to satisfy assume() in f')
+ where <built-in method startswith of str object> = ''.startswith
+ where '' = TestCaseObservation(..., status='gave_up', status_reason='', ...).status_reasonCause
This comes from a CPython bug, python/cpython#158121: when one sys.monitoring tool's LINE callback returns DISABLE, another tool misses the INSTRUCTION event for that line's first instruction, on the execution where DISABLE is returned. It affects 3.12 through CPython main.
The two tools that meet here:
With observability enabled, _should_trace() turns on coverage collection. scrutineer.Tracer.trace_line returns sys.monitoring.DISABLE for files it doesn't trace, including hypothesis/control.py. CrossHair listens for INSTRUCTION events. For an f-string, it replaces the operands of BUILD_STRING with "" and puts the real result back when the next instruction's event fires. In assume(), the f-string f"failed to satisfy {where}" is followed by location=_calling_frame_location(frame) on a new source line. The event for that line's first instruction never reaches CrossHair, so the result is never restored. UnsatisfiedAssumption gets reason='', while location is correct.
Setting hypothesis.internal.observability.OBSERVABILITY_COLLECT_COVERAGE = False makes the test pass.
Options on the Hypothesis side
- Mark the test xfail_on_crosshair until the CPython fix is available.
- Skip observability coverage collection when the backend is crosshair. This also covers other code evaluated under crosshair with observability on, not just this test
Source: HypothesisWorks/hypothesis