Hypothesis

hypothesis.works ↗

A Python property-based testing library that generates inputs to challenge the properties your code should preserve.

SI Score
80/100
Pricing
Open Source AI reading, not confirmed
Free plan
Not confirmed
Sign-up required
Not confirmed

Ask SI about Hypothesis

Answers use saved listing facts and recorded sources.
Homepage screenshot
Screenshot of the Hypothesis homepage

What it does

Hypothesis adds property-based tests to Python projects. Instead of writing only a short list of example inputs, a developer states a rule the code should satisfy and chooses a strategy for valid inputs. Hypothesis generates examples, reports counterexamples when a rule fails, and can simplify a failing input to make the problem easier to understand. It integrates with ordinary Python test functions and is particularly useful for parsers, data transformations, and boundary-heavy logic.

State the rule, then explore its inputs

Install the Hypothesis package in a Python project and write a test that describes an invariant rather than a few hand-picked examples. The official quickstart uses the @given decorator with built-in strategies such as integers and text. For instance, a test for a text-normalization function could assert that normalizing its output a second time leaves it unchanged. That is an illustrative property, not a test performed for this listing.

Hypothesis supplies many input examples to the test and records a counterexample when the property fails; its failure reports can reduce an input to a simpler case. This is useful when edge cases are hard to enumerate, but the developer must choose a correct property and a strategy that represents the inputs the application really accepts. It complements example-based and integration tests rather than deciding whether the product behavior is correct.

The Python library is maintained in the HypothesisWorks repositories and is licensed under MPL 2.0. The package's license file notes that some reused code retains its original license notices, so teams redistributing the library should review those notices as well.

Strengths

  • Generates many values from a declared strategy instead of relying only on manually selected examples.
  • Failure reports can present a smaller counterexample to help identify the input that breaks a property.
  • The Python package is available under MPL 2.0, with its official license file describing the treatment of reused code.

Watch out for

  • Useful results depend on the developer choosing sound invariants and input strategies; the library cannot infer the intended behavior.

Best for

  • Python developers testing parsers, encoders, transformations, and other edge-case-heavy logic
  • Projects where expected behavior can be expressed as properties over many generated inputs
  • Teams that want to complement example-based tests with automatically explored cases

Sources