Testing and Diagnostics Modules

unittest

Organizes automated checks into TestCase objects and suites, with assertions, fixture hooks and result reporting. TestResult records failures (failed assertions) separately from unexpected errors. A passing test suite supports only the behaviors its assertions cover.

Formal Syntax & Structure

python syntaxpython
import unittest

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import unittestclass TotalTest(unittest.TestCase):    def runTest(self):        self.assertEqual(sum([2, 3]), 5)result = TotalTest().run()print(result.testsRun, result.wasSuccessful())
Python Reference