Skip to main content

Level-up your Hypothesis tests with CrossHair.

Project description

hypothesis-crosshair

Downloads

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.

FAQ

Can I try using crosshair for ALL my hypothesis tests?

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 

Changelog

Next Version

  • Nothing yet!

0.0.29

  • Fix a mismatch in time units used by CrossHair >= 0.0.106 and the plugin. Re-aligned and set minimum CrossHair version to 0.0.106.

0.0.28

  • Implement the replay_choices provider hook, letting Hypothesis warm-start CrossHair with high-coverage choice sequences (for example, a corpus found by HypoFuzz). Each enqueued sequence is handed to CrossHair's new smt_for_unification API, biasing the solver so that user-code branches taken under the seed are recorded in the search tree; follow-up (unseeded) iterations then explore the sibling branches the seed left unvisited. (fixes #26)

0.0.27

  • Prevent a NotDeterministic exception from escaping during post-test-run realization.

0.0.26

  • 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)

0.0.25

  • 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)

0.0.24

  • Do not attempt to capture and retry hypothesis internal exceptions. (fixes #34)

0.0.23

0.0.22

  • Abort concrete executions with invalid draws. (fixes #29)
  • Adjust how the preventative measures in v0.0.21 work for recursive datastructures.

0.0.21

  • Avoid occasional unexpected errors when stopping a test run with Ctrl-C.
  • Prevent over-expansion when generating recursive datastructures. (fixes #27)

0.0.20

  • Avoid potential import warning when registering ourself with hypothesis.
  • Skip constraint checking when performing a concrete re-execution.

0.0.19

  • 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.

0.0.18

  • Ensure drawn floats respect hypothesis signed-zero semantics for min_value/max_value.

0.0.17

  • 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_case instead of verified. This lets Hypothesis report unsatisfiable strategies correctly when run under crosshair.

0.0.16

  • 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.

0.0.15

  • (was never released)

0.0.14

  • Support the revised hypothesis provider draw interfaces as of hypothesis v6.112.0.

0.0.13

0.0.12

  • Error early when trying to nest hypothesis tests. (which will otherwise put CrossHair into a bad state)

0.0.11

  • Address errors when the solver can't keep up (fixes #20)

0.0.10

  • Reduce the numebr of iterations required to generate valid datetimes

0.0.9

  • Quietly ignore iterations that appear to be failing due to symbolic intolerance.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hypothesis_crosshair-0.0.29.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hypothesis_crosshair-0.0.29-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file hypothesis_crosshair-0.0.29.tar.gz.

File metadata

  • Download URL: hypothesis_crosshair-0.0.29.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for hypothesis_crosshair-0.0.29.tar.gz
Algorithm Hash digest
SHA256 603c728ec4df5c10841fcade91eb670cabef0a9690a9ba26dd4b380c6efc4eb1
MD5 9ee9cb91b27d14a232c658de470f8384
BLAKE2b-256 d7ce075ebdeb53d17964fda7f99d0e9445606ad326e4a248eb675a898c2e7660

See more details on using hashes here.

File details

Details for the file hypothesis_crosshair-0.0.29-py3-none-any.whl.

File metadata

File hashes

Hashes for hypothesis_crosshair-0.0.29-py3-none-any.whl
Algorithm Hash digest
SHA256 f49efbe023b99b017bdb2ab42dafb3db457196cf3cfe168576cd40c62571c7e4
MD5 f7b780f31ea7f3d027664973867a3f88
BLAKE2b-256 99c9fcfcced6948d7b3d7f9b381c6953ad1afd3d495501cf72bdeb4c36649065

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page