Hypothesis
Hypothesis generates thousands of random inputs to find edge cases your example-based tests miss.
Hypothesis generates thousands of random inputs to find edge cases your example-based tests miss.
from hypothesis import given, strategies as st
@given(st.integers(), st.integers())
def test_addition_commutative(a, b):
assert a + b == b + a
@given(st.lists(st.integers()))
def test_sort_is_idempotent(lst):
assert sorted(sorted(lst)) == sorted(lst)
@given(st.text(min_size=1))
def test_upper_lower_roundtrip(s):
assert s.upper().lower() == s.lower()
Hypothesis remembers failing examples in its database and replays them on every subsequent run.