There are various libraries and frameworks that help us unit test Python code, such as pytest and nose2. Python even comes with a module called unittest. The choice of testing framework is up to the developer. In this lesson, we’ll familiarize ourselves with the pytest library.

The pytest library

The pytest library, along with auxiliary libraries like pytest-cov and coverage, help us unit test code and allow us to gain insights into how much of the code has been tested.

Test cases

Consider the following example module:

Get hands-on with 1200+ tech skills courses.