36.2 Automated Testing
Python's standard library provides two modules for test-driven development, a type of programming in which many small sections of the program, referred to as units, are checked for errors by automated test runs. In test-driven development, the program is developed in small, self-contained steps until it passes all previous tests and all added tests again. This way, adding new code won’t allow bugs to creep into old, already tested code.
In Python, the concept of unit tests that you may be familiar with is implemented in the unittest module. The doctest module makes it possible to place test cases within a docstring—for example, of a function. In the following sections, we’ll first deal with the doctest module and then ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access