Integrating with doctest

Let's explore how doctest can be integrated.

We'll cover the following

The unittest module can be used with Python’s doctest module as well. If we have created a lot of modules that have doctests in them, we will usually want to be able to run them systematically. This is where unittest comes in. The unittest module supports Test Discovery starting in Python 3.2. Test Discovery basically allows unittest to look at the contents of a directory and determine from the file name which ones might contain tests. It then loads the test by importing them.

Creating a file

We will create a file called It will need to have the following code:

Get hands-on with 1200+ tech skills courses.