HypothesisWorks /hypothesis
The property-based testing library for Python
★ 9,170⑂ 701👁 64⑃ 3,142● 1,803▤ 1,032
+2
Daily
9,170
stars
701
forks
64
watchers
3,142
prs
1,803
issues
1,032
releases
README
Hypothesis
Website
Documentation
Source code
Contributing
Community
Hypothesis is the property-based testing library for Python. With Hypothesis, you write tests which should pass for all inputs in whatever range you describe, and let Hypothesis randomly choose which of those inputs to check - including edge cases you might not have thought about. For example:
python
from hypothesis import given, strategies as st
@given(st.lists(st.integers()))
def test_matches_builtin(ls):
assert sorted(ls) == my_sort(ls)
This randomized testing can catch bugs and edge cases that you didn't think of and wouldn't have found. In addition, when Hypothesis does find a bug, it doesn't just report any failing test case — it reports the simplest possible one. This makes property-based tests a powerful tool for debugging, as well as testing.
For instance,
python
def my_sort(ls):
return sorted(set(ls))
fails with the simplest possible failing test case:
Failing test case: test_matches_builtin(ls=[0, 0])
Installation
To install Hypothesis:
pip install hypothesis
There are also optional extras available.Top issues
#59When using class based tests, setUp is not called for each hypothesis test14 comments · 2015-04-16#1804Full support for all grammars in Lark examples12 comments · 2019-02-10#2437Add option to insert whitespace between tokens in lark strategy11 comments · 2020-05-18#3131Add a strategy for new Numpy PRNGs10 comments · 2021-11-02#4740Migrate the Hypothesis engine from Python to Rust8 comments · 2026-05-25#4681Impersonating functions can affect tracebacks in unintended ways5 comments · 2026-03-24#4572Support PEP 7944 comments · 2025-10-24#4170Document `DataObject.draw` and rename other members with leading underscore4 comments · 2024-11-11
Latest release
Hypothesis version 6.170.15 v6.170.15 2026-11-06Hypothesis now has 100% type coverage of our public API, as checked by pyrefly. The canonical version of these notes (with links) is on readthedocs.