diff --git a/docs/writing/tests.rst b/docs/writing/tests.rst index 23e0f01..542003b 100644 --- a/docs/writing/tests.rst +++ b/docs/writing/tests.rst @@ -190,6 +190,40 @@ the unittest module! `py.test `_ +Hypothesis +---------- + +Hypothesis is a library which lets you write tests that are parametrized by +a source of examples. It then generates simple and comprehensible examples +that make your tests fail, letting you find more bugs with less work. + +.. code-block:: console + + $ pip install hypothesis + +For example, testing lists of floats will try many examples, but report the +minimal example of each bug (distinguished exception type and location): + +.. code-block:: python + + @given(lists(floats(allow_nan=False, allow_infinity=False), min_size=1)) + def test_mean(xs): + mean = sum(xs) / len(xs) + assert min(xs) <= mean(xs) <= max(xs) + +.. code-block:: + + Falsifying example: test_mean( + xs=[1.7976321109618856e+308, 6.102390043022755e+303] + ) + +Hypothesis is practical as well as very powerful, and will often find bugs +that escaped all other forms of testing. It integrates well with py.test, +and has a strong focus on usability in both simple and advanced scenarios. + + `hypothesis `_ + + tox ---