CheckOps
Hypothesis
Hypothesis is the MPL-2.0 property-based testing library for Python: describe the range of inputs, let it generate cases including edge cases, and get the simplest failing example when a property breaks.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
Hypothesis is the property-based testing library for Python. Instead of writing individual examples, you write tests that should pass for all inputs in a range you describe, and Hypothesis chooses which inputs to try, including edge cases you might not have thought about.
Its README shows the core idea with a sorting example: a test asserts that sorted(ls) == my_sort(ls) for any list of integers. When my_sort is implemented as sorted(set(ls)), Hypothesis does not just report a random failing list; it shrinks the input and reports the simplest failing case, ls=[0, 0]. That shrinking is what makes property-based tests useful for debugging as well as testing.
Hypothesis integrates with pytest and unittest, stores failing examples in a local database so they are replayed on the next run, and provides strategies for built-in types, dates, text, data frames (via extras) and your own classes. It also supports stateful testing, where Hypothesis generates sequences of operations against a model of your system.
The library is licensed under the Mozilla Public License 2.0 and released very frequently; version 6.170.15 was published on 6 November 2026. In the quality loop, it strengthens unit tests for parsers, serialisers, algorithms and business rules.
The source code is at HypothesisWorks/hypothesis on GitHub under the MPL-2.0 licence, with about 9,200 stars; the most recent commit was on 8 November 2026.
How it compares: property-based testing started with QuickCheck for Haskell, and most languages now have a port. Hypothesis is notable for its shrinking approach, which works on the underlying choice sequence rather than requiring a hand-written shrinker per type, so custom strategies shrink well automatically. That design has influenced libraries in other ecosystems. Compared with example-based pytest tests, Hypothesis tests are fewer but broader; many teams keep both, using examples to document expected behaviour and properties to search for the unexpected. Hypothesis also offers a ghostwriter command that drafts property tests for existing functions, which is a useful starting point when adopting it on an older codebase.
Health checks are another practical detail: Hypothesis warns when a strategy filters out too many examples or when data generation is unusually slow, which helps you write efficient strategies instead of silently testing very little.
Features
- Strategies:
hypothesis.strategiesgenerates integers, floats, text, lists, dictionaries, dates, UUIDs and more, and composes them withbuilds,composite,mapandfilter. - Shrinking: Failing inputs are reduced to a minimal example that is easy to understand and reproduce.
- Example database: Failing examples are saved locally and replayed first on later runs, so a found bug is not lost.
- pytest integration:
@givenworks with pytest fixtures, parametrisation and plugins. - Settings and profiles: Control the number of examples, deadlines and health checks, with separate profiles for local and CI runs.
- Stateful testing: Rule-based state machines generate sequences of actions to test APIs and data structures with internal state.
- Explicit examples:
@example(...)pins important cases so they always run alongside generated ones. - Extras: Optional strategies for libraries such as NumPy, pandas and Django, listed in the docs.
Pros
- Finds real edge cases: Empty lists, duplicates, Unicode, NaN and boundary values come up naturally.
- Free to use: Open source under the MPL-2.0 licence, so the core tool costs nothing to use.
- Actively maintained: The repository had commits as recent as 8 November 2026.
- Community: About 9,200 GitHub stars.
Cons
- Thinking in properties: Writing good properties (round trips, invariants, model comparisons) takes practice.
- Slower than example tests: Each test runs many examples; deadlines and example counts need tuning for big suites.
- Flaky external dependencies: Tests that hit networks or clocks interact poorly with repeated generation.
- Python only: Other languages need their own libraries, such as fast-check, jqwik or proptest.
Usage and Links (Example)
Install and write a property test with pytest:
pip install hypothesis
from hypothesis import given, strategies as st
import json
@given(st.dictionaries(st.text(), st.integers()))
def test_json_round_trip(d):
assert json.loads(json.dumps(d)) == d
Pin a known edge case and tune settings:
from hypothesis import example, settings
@settings(max_examples=500)
@given(st.text())
@example("")
def test_slugify_is_idempotent(s):
assert slugify(slugify(s)) == slugify(s)
Register a faster profile for pull requests and a deeper one for nightly runs:
from hypothesis import settings
settings.register_profile("ci", max_examples=200)
settings.register_profile("nightly", max_examples=5000)
Practical tips:
- Start with round-trip properties (encode/decode, serialise/parse); they are easy and catch many bugs.
- Compare against a simple reference implementation when optimising code.
- Commit the shrunk failing case as an
@exampleonce fixed, so it stays covered.
Resources:
Pricing
Hypothesis is free and open source under the MPL-2.0 licence.
Recommended for?
- Python developers testing parsers, serialisers, algorithms and validation logic.
- Library maintainers who want broader input coverage than hand-picked examples.
- Teams with tricky state, using stateful testing to explore sequences of operations.
- Not a fit for tests dominated by slow external systems.
Conclusion
Hypothesis brings mature property-based testing to Python, with excellent shrinking, a replay database and tight pytest integration.
A handful of well-chosen properties often finds bugs that hundreds of example tests miss, which makes it one of the highest-value additions to a Python test suite.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with Hypothesis side by side.
- Ppytestpytest is the usual Python test runner: plain asserts, fixtures, parametrization, and a large plugin set.Compare with Hypothesis
Ffast-checkfast-check is an MIT-licensed property-based testing framework for JavaScript and TypeScript, with rich arbitraries, shrinking, replayable seeds, model-based testing and race-condition detection.Compare with Hypothesis
Jjqwikjqwik is an EPL-2.0 property-based testing engine for the JUnit Platform, letting Java and Kotlin developers write properties with generated, shrinking inputs alongside regular JUnit 5 tests.Compare with Hypothesis
Pproptestproptest is a Hypothesis-inspired property-based testing framework for Rust, with composable strategies, automatic shrinking and persisted regression files.Compare with Hypothesis
Mmutmutmutmut is a BSD-3-Clause mutation testing tool for Python that changes your code in small ways and reports which mutants your tests fail to kill, with a terminal UI for browsing results.Compare with Hypothesis
CCoverage.pyCoverage.py is the standard Apache-2.0 code coverage tool for Python, measuring line and branch coverage and producing terminal, HTML, XML, JSON and LCOV reports; pytest-cov builds on it.Compare with Hypothesis