About this project
Hypothesis is a property-based testing library for Python. Instead of writing tests with fixed inputs, developers describe the range of inputs a function should handle, and Hypothesis randomly generates test cases from that range—including edge cases the developer may not have anticipated.
The core workflow uses the @given decorator and a strategies module. For example, a test can be written as @given(st.lists(st.integers())) to automatically generate lists of integers and verify that a custom sort function matches Python's built-in sorted(). This approach catches bugs and edge cases that would be missed by hand-written test cases.
When Hypothesis finds a failing test, it does not report an arbitrary failing input. Instead, it shrinks the failing case to the simplest possible one, making debugging significantly easier. For instance, if a sort function incorrectly deduplicates input, Hypothesis reports the minimal failing case such as ls=[0, 0] rather than a large random list.
Installation is straightforward via pip install hypothesis. Optional extras are available for additional functionality. The project includes documentation, a website, and a community section for contributors and users.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.