Skip to the content
Know your tech before you buy it. Makers: get listed from $49/mo

unittest

docs.python.org

  • Free plan
  • Windows
  • macOS
  • Linux
7.2 Club score Visit docs.python.org

What unittest is

unittest is Python’s unit testing framework for organizing and automating tests, including their setup, execution, and reporting. Its core parts include fixtures for shared setup and cleanup, TestCase classes, TestSuite collections, and test runners. TestCase provides assertions such as assertEqual, assertTrue, assertFalse, and assertRaises to record outcomes. Tests can be run from the command line by module, class, method, or file path; starting without arguments begins test discovery. Discovery can be configured with a start directory, filename pattern, and project top-level directory, but test files must be importable modules or packages from that top level. The framework also supports skipped tests, expected failures, and subtests that report iteration parameters when a subtest fails. The Python documentation points to unittest.mock for substituting mock objects and checking their use. Production test runs can be driven by continuous integration systems including Buildbot, Jenkins, GitHub Actions, and AppVeyor. unittest supports Python on Linux, macOS, and Windows, and is free to use and distribute, including commercially, under Python’s OSI-approved open-source license.

Who it suits

unittest suits Python developers who need to organize, run, and automate unit tests. Its fixtures, discovery options, and subtests support teams building structured test suites.

Good to know, and what to watch

  • Includes fixtures, TestCase, TestSuite, and test runners.
  • Command-line runs can target modules, classes, methods, or files.
  • Supports test discovery and configurable filename patterns.
  • Offers skipping, expected failures, and subtests.
  • Free to use and distribute commercially.
  • Discovery requires test files to be importable from the project top level.
  • Supports Python tests rather than multiple languages.

Free

Free

Free plan

The verdict

unittest provides test organization, assertions, discovery, and execution as part of Python’s standard library. Its importability requirement is worth checking when setting up test discovery.

What the maker publishes

Assertions
TestCase includes assertion methods such as assertEqual, assertTrue, assertFalse, and assertRaises to record test outcomes. source
Command line
Tests can be run from the command line by module, class, method, or file path, and running without arguments starts test discovery. source
Compatibility limitation
Test discovery requires test files to be importable modules or packages from the project top-level directory. source
Integrations
The documentation recommends driving production tests with continuous integration systems such as Buildbot, Jenkins, GitHub Actions, or AppVeyor. source
Maintainer organization
The Python Software Foundation says it supports and maintains Python documentation, python.org, PyPI, and other services used by the Python community. source
Mock support
The documentation points to unittest.mock as a library for replacing parts of a system under test with mock objects and making assertions about their use. source
Platforms
Python.org lists downloads or platform pages for Windows, macOS, Android, iOS, and other platforms. source
Purpose
unittest is a unit testing framework that supports test automation, setup and cleanup sharing, test collection, and independence from the reporting framework. source
Security and license
Python is developed under an OSI-approved open source license and is freely usable and distributable, including commercially. source
Skipping and expected failures
Tests and classes can be skipped conditionally or unconditionally, and tests can be marked as expected failures. source
Subtests
The subTest context manager distinguishes iterations within a test method and reports parameters when a subtest fails. source
Test building blocks
It provides fixtures, TestCase, TestSuite, and test runners for organizing and executing tests. source
Test discovery
The framework supports discovery from a project directory and provides options to set the start directory, filename pattern, and project top-level directory. source

Checked against the maker's pages on 9 Oct 2026.