Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ce7530b

Browse filesBrowse files
committed
New testing tool: Hypothesis
Based on README at https://github.com/HypothesisWorks/hypothesis-python
1 parent 39b0911 commit ce7530b
Copy full SHA for ce7530b

File tree

Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed

‎docs/writing/tests.rst

Copy file name to clipboardExpand all lines: docs/writing/tests.rst
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,40 @@ the unittest module!
190190
`py.test <https://docs.pytest.org/en/latest/>`_
191191

192192

193+
Hypothesis
194+
----------
195+
196+
Hypothesis is a library which lets you write tests that are parametrized by
197+
a source of examples. It then generates simple and comprehensible examples
198+
that make your tests fail, letting you find more bugs with less work.
199+
200+
.. code-block:: console
201+
202+
$ pip install hypothesis
203+
204+
For example, testing lists of floats will try many examples, but report the
205+
minimal example of each bug (distinguished exception type and location):
206+
207+
.. code-block:: python
208+
209+
@given(lists(floats(allow_nan=False, allow_infinity=False), min_size=1))
210+
def test_mean(xs):
211+
mean = sum(xs) / len(xs)
212+
assert min(xs) <= mean(xs) <= max(xs)
213+
214+
.. code-block::
215+
216+
Falsifying example: test_mean(
217+
xs=[1.7976321109618856e+308, 6.102390043022755e+303]
218+
)
219+
220+
Hypothesis is practical as well as very powerful, and will often find bugs
221+
that escaped all other forms of testing. It integrates well with py.test,
222+
and has a strong focus on usability in both simple and advanced scenarios.
223+
224+
`hypothesis <https://hypothesis.readthedocs.io/en/latest/>`_
225+
226+
193227
tox
194228
---
195229

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.