Add the power of solver-based symbolic execution to your Hypothesis tests with CrossHair.
Just
pip install hypothesis-crosshair
and then add a backend="crosshair" setting, like so:
from hypothesis import given, settings, strategies as st
@settings(backend="crosshair")
@given(st.integers())
def test_needs_solver(x):
assert x != 123456789
Docs hopefully coming soon. In the meantime, start a discussion or file an issue.
Yes! Create or edit your pytest conftest.py file to register a profile like the following:
from hypothesis import settings
settings.register_profile(
"crosshair",
backend="crosshair",
)
And then run pytest using the profile you've defined:
pytest . --hypothesis-profile=crosshair
- Nothing yet
- Prevent a NotDeterministic exception from escaping during post-test-run realization.
- Ensure CrossHair respects the no-characters-allowed constraint (
st.characters(alphabet="")). This strategy should now produce only the empty string. (previously CrossHair would allow it to produce any string)
- Prevent internal crosshair errors from getting exposed while trying to recover from a user-level exception.
- Synchronize with recent hypothesis API updates. (fixes #40 and #42)
- Do not attempt to capture and retry hypothesis internal exceptions. (fixes #34)
- Prevent an incorrect verified claim under SMT-heavy analysis. (fixes pschanely/CrossHair#354)
- Abort concrete executions with invalid draws. (fixes #29)
- Adjust how the preventative measures in v0.0.21 work for recursive datastructures.
- Avoid occasional unexpected errors when stopping a test run with Ctrl-C.
- Prevent over-expansion when generating recursive datastructures. (fixes #27)
- Avoid potential import warning when registering ourself with hypothesis.
- Skip constraint checking when performing a concrete re-execution.
- Limit the re-thow behavior in 0.0.17 to Unsatisfiable errors exclusively
- Change default path timeout to 2.5 seconds
- Prevent false positives by ensuring user exceptions are only exposed under concrete executions.
- Ensure drawn floats respect hypothesis signed-zero semantics for min_value/max_value.
- Do not interpret Unsatisfiable errors as user exceptions; just re-throw, so that hypothesis can act appropriately.
- Report CrossHair path abortions to hypothesis as
discard_test_caseinstead ofverified. This lets Hypothesis report unsatisfiable strategies correctly when run under crosshair.
- Integrate hypothesis's new BackCannotProceed exception, which will reduce the likelihood of FlakeyReplay errors.
- Validate suspected counterexamples with concrete executions.
- Treat nondeterminism as an unexplored path rather than a user error. (though we might change this back later)
- Ensure realization logic called by hypothesis cannot grow the path tree.
- Allow for collapsing more SMT expressions when drawing strings and floats.
- (was never released)
- Support the revised hypothesis provider draw interfaces as of hypothesis
v6.112.0.
- Integrate with the hypothesis observability system.
- Error early when trying to nest hypothesis tests. (which will otherwise put CrossHair into a bad state)
- Address errors when the solver can't keep up (fixes #20)
- Reduce the numebr of iterations required to generate valid datetimes
- Quietly ignore iterations that appear to be failing due to symbolic intolerance.