hypothesis: Property-based Testing in Python

If you want to test some properties or assumptions, it can be cumbersome to write a wide range of scenarios.

To automatically run your tests against a wide range of scenarios and find edge cases in your code that you would otherwise have missed, use hypothesis.

In the code above, I test if the addition of two floats is commutative. The test fails when either x or y is NaN. Now I can rewrite my code to make it more robust against these edge cases.

Learn more about hypothesis here.

Link to my previous tips about testing.

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran