Last Updated: June 6, 2026
Python ships with a test framework built into the standard library: unittest. You don't install anything, you don't add a dependency, you just import unittest and start writing test classes. This chapter covers the framework's mechanics: how to subclass TestCase, how the assertion methods work, what setUp and tearDown do, how to run the tests, and how to skip the ones that don't apply. Knowing unittest matters because the standard library uses it, many older codebases are built on it, and the lifecycle ideas show up in every test framework you'll ever touch.