15.6 Unit testing with the pytest module
The pytest tool allows us to step beyond the examples used by doctest in docstrings. Instead of using a subclass of TestCase, the pytest tool lets us use function definitions. The pytest approach uses Python’s built-in assert statement, leaving the test case looking somewhat simpler.
The pytest tool is not part of Python; it needs to be installed separately. Use a command like this:
(cookbook3) % python -m pip install pytest
In this recipe, we’ll look at how we can use pytest to simplify our test cases.
15.6.1 Getting ready
The Gherkin language can help to structure a test. For this recipe, we have a scenario like this:
Scenario: Summary object can add values and compute statistics.
Given a Summary object
And numbers in the range 0 to 1000 (inclusive) shuffled randomly
When all numbers are added to the Summary object
Then...