Skip to content
SPECIFICTION
Get listed

unittest

docs.python.org

Free plan WindowsmacOSLinux
Visit docs.python.org
Spec score 7.3 #22 of 32 in Unit Testing

What it is

unittest is Python’s free unit-testing framework for automating test setup, execution and outcome reporting. Fixtures provide shared setup and cleanup, while TestCase, TestSuite and test runners organize and run tests. TestCase includes assertions such as assertEqual, assertTrue, assertFalse and assertRaises. Tests can run from the command line by module, class, method or file path; running without arguments starts 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. Tests and classes may be skipped conditionally or unconditionally, and expected failures can be marked. The subTest context manager separates iterations and reports parameters when one fails. unittest.mock supports replacing system parts with mock objects and checking their use. Documentation recommends CI systems including Buildbot, Jenkins, GitHub Actions and AppVeyor. It runs on Linux, macOS and Windows, and is free to use and distribute commercially under Python’s OSI-approved open source license.

Spec sheet

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

Plans and prices

Free Free Free to use and distribute, including for commercial use Python standard library unit testing framework · no separate unittest price stated Read 9 Oct 2026 · python.org

Every unittest plan and price →

Strong points and limits

Strong points

  • Free commercial use and distribution
  • Built-in fixtures and test runners
  • Command-line test discovery
  • Supports skips and expected failures
  • Includes unittest.mock guidance

Limits

  • Discovery requires importable test modules
  • Supports Python only
  • No separate free trial

Who it suits

It suits Python developers who need built-in unit-test organization, command-line discovery, assertions, mocks and CI integration across Linux, macOS or Windows.

Verdict

unittest provides the core structures and command-line workflow needed for Python unit testing. Its discovery rule is important when organizing project directories.

Where Specifiction places it

Alternatives to unittestAll alternatives →