Skip to content

HypothesisWorks/hypothesis

Folders and files

NameName
Last commit message
Last commit date
Apr 11, 2025
Oct 15, 2023
Aug 18, 2021
Apr 6, 2025
Apr 25, 2025
Mar 27, 2021
Aug 20, 2024
Apr 23, 2025
Dec 30, 2019
Apr 23, 2025
Apr 5, 2025
Mar 30, 2025
Jun 25, 2019
May 22, 2024
Jan 15, 2025
Apr 9, 2025
Aug 14, 2021
Dec 29, 2024
Apr 10, 2022
Oct 9, 2024
Jan 8, 2019
Apr 21, 2018
Apr 2, 2025
Apr 23, 2025
Nov 21, 2019
Nov 20, 2019
Mar 18, 2025
Mar 24, 2024

Repository files navigation

Hypothesis

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:

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,

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.