Frameworks and libraries for unit testing

In this section, we will discuss two frameworks for writing and running unit tests. The first one, unittest, is available in the standard library of Python, while the second one, pytest, has to be installed externally via pip.

When it comes to covering testing scenarios for our code, unittest alone will most likely suffice, since it has plenty of helpers. However, for more complex systems on which we have multiple dependencies, connections to external systems, and probably the need to patch objects, and define fixtures parameterize test cases, then pytest looks like a more complete option.

We will ...

Get Clean Code in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.