https://github.com/hypothesisworks/hypothesis
The property-based testing library for Python
https://github.com/hypothesisworks/hypothesis
fuzzing property-based-testing python testing
Last synced: 5 days ago
JSON representation
The property-based testing library for Python
- Host: GitHub
- URL: https://github.com/hypothesisworks/hypothesis
- Owner: HypothesisWorks
- License: other
- Created: 2013-03-10T13:51:19.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2025-05-04T00:08:30.000Z (14 days ago)
- Last Synced: 2025-05-05T17:21:16.330Z (12 days ago)
- Topics: fuzzing, property-based-testing, python, testing
- Language: Python
- Homepage: https://hypothesis.works
- Size: 38.1 MB
- Stars: 7,828
- Watchers: 69
- Forks: 601
- Open Issues: 66
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.rst
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.rst
- Citation: CITATION.cff
- Codeowners: CODEOWNERS
- Authors: AUTHORS.rst
Awesome Lists containing this project
README
![]()
# Hypothesis
* [Website](https://hypothesis.works/)
* [Documentation](https://hypothesis.readthedocs.io/en/latest/)
* [Source code](https://github.com/hypothesisWorks/hypothesis/)
* [Contributing](https://github.com/HypothesisWorks/hypothesis/blob/master/CONTRIBUTING.rst)
* [Community](https://hypothesis.readthedocs.io/en/latest/community.html)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 example — 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 example:
```
Falsifying example: test_matches_builtin(ls=[0, 0])
```### Installation
To install Hypothesis:
```
pip install hypothesis
```There are also [optional extras available](https://hypothesis.readthedocs.io/en/latest/extras.html).