CrossHair is an analysis tool for Python that utilizes symbolic execution to blur the line between traditional testing and type systems. It works by repeatedly calling functions with symbolic inputs and employing an SMT solver to explore execution paths, finding counterexamples to contracts defined within docstrings. The library currently stands at version 0.0.102 and has a fairly active release cadence with frequent minor updates.
pip install crosshair-toolVerified import paths — ran on the pinned version, not inferred.
Install CrossHair and then run it from the command line to watch your code for contract violations. Define post-conditions and other contracts within function docstrings. CrossHair will continuously analyze the specified files and report any counterexamples.
Add `math.isfinite(x)` preconditions to your contracts for float arguments as appropriate, or set the environment variable `CROSSHAIR_ONLY_FINITE_FLOATS=1` to revert to previous behavior temporarily.
Adjust your command-line arguments to use `--max_uninteresting_iterations` instead of or in conjunction with `timeout` options, as it will adapt analysis time to problem difficulty.
Update scripts to use `--example_output_format=arg_dictionary` when using the `cover` command.
Be aware that caching will not be active during CrossHair analysis. Design contracts such that their correctness does not implicitly depend on the side effects or memoization provided by these caches during analysis.
Be patient during installation. Ensure you have the necessary build tools (e.g., C++ compiler) installed for your operating system.