From ce7530bc70b7aca2553aebb7b7cd6303c9556827 Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Mon, 27 Nov 2017 13:58:59 +1100 Subject: [PATCH] New testing tool: Hypothesis Based on README at https://github.com/HypothesisWorks/hypothesis-python --- docs/writing/tests.rst | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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 ---