[ ![Python logo](../_static/py.svg) ](https://www.python.org/)

Theme  Auto  Light  Dark

###  [ Table of Contents ](../contents.html)

  * ` unittest  ` â Unit testing framework 
    * Basic example 
    * Command-Line Interface 
      * Command-line options 
    * Test Discovery 
    * Organizing test code 
    * Re-using old test code 
    * Skipping tests and expected failures 
    * Distinguishing test iterations using subtests 
    * Classes and functions 
      * Test cases 
      * Grouping tests 
      * Loading and running tests 
        * load_tests Protocol 
    * Class and Module Fixtures 
      * setUpClass and tearDownClass 
      * setUpModule and tearDownModule 
    * Signal Handling 

####  Previous topic

[ ` doctest  ` â Test interactive Python examples ](doctest.html "previous
chapter")

####  Next topic

[ ` unittest.mock  ` â mock object library ](unittest.mock.html "next
chapter")

###  This Page

  * [ Report a Bug ](../bugs.html)
  * [ Show Source ](https://github.com/python/cpython/blob/main/Doc/library/unittest.rst)

###  Navigation

  * [ index ](../genindex.html "General Index")
  * [ modules ](../py-modindex.html "Python Module Index") | 
  * [ next ](unittest.mock.html "unittest.mock â mock object library") | 
  * [ previous ](doctest.html "doctest â Test interactive Python examples") | 
  * ![Python logo](../_static/py.svg)
  * [ Python ](https://www.python.org/) » 
  *   *   * [ 3.12.3 Documentation ](../index.html) » 
  * [ The Python Standard Library ](index.html) » 
  * [ Development Tools ](development.html) » 
  * [ ` unittest  ` â Unit testing framework ]()
  * | 
  * Theme  Auto  Light  Dark  | 

#  ` unittest  ` â Unit testing framework  Â¶

**Source code:** [ Lib/unittest/__init__.py
](https://github.com/python/cpython/tree/3.12/Lib/unittest/__init__.py)

* * *

(If you are already familiar with the basic concepts of testing, you might
want to skip to  the list of assert methods  .)

The  ` unittest  ` unit testing framework was originally inspired by JUnit and
has a similar flavor as major unit testing frameworks in other languages. It
supports test automation, sharing of setup and shutdown code for tests,
aggregation of tests into collections, and independence of the tests from the
reporting framework.

To achieve this,  ` unittest  ` supports some important concepts in an object-
oriented way:

test fixture

    

A _test fixture_ represents the preparation needed to perform one or more
tests, and any associated cleanup actions. This may involve, for example,
creating temporary or proxy databases, directories, or starting a server
process.

test case

    

A _test case_ is the individual unit of testing. It checks for a specific
response to a particular set of inputs.  ` unittest  ` provides a base class,
` TestCase  ` , which may be used to create new test cases.

test suite

    

A _test suite_ is a collection of test cases, test suites, or both. It is used
to aggregate tests that should be executed together.

test runner

    

A _test runner_ is a component which orchestrates the execution of tests and
provides the outcome to the user. The runner may use a graphical interface, a
textual interface, or return a special value to indicate the results of
executing the tests.

See also

Module [ ` doctest  ` ](doctest.html#module-doctest "doctest: Test pieces of
code within docstrings.")

    

Another test-support module with a very different flavor.

[ Simple Smalltalk Testing: With Patterns
](https://web.archive.org/web/20150315073817/http://www.xprogramming.com/testfram.htm)

    

Kent Beckâs original paper on testing frameworks using the pattern shared by
` unittest  ` .

[ pytest ](https://docs.pytest.org/)

    

Third-party unittest framework with a lighter-weight syntax for writing tests.
For example, ` assert  func(10)  ==  42  ` .

[ The Python Testing Tools Taxonomy
](https://wiki.python.org/moin/PythonTestingToolsTaxonomy)

    

An extensive list of P