On this page
unittest.TestSuite
Prev: unittest.TestResult | Up: unittest | Next: unittest.TextTestResult
Rel: unittest.addModuleCleanup, unittest.doModuleCleanups, unittest.enterModuleContext, unittest.expectedFailure
Ref: docs.python.org — unittest.TestSuite
Tags: #public #python3 #stdlib #unittest
Import
import unittest
from unittest import TestSuite
Signature & Overview
unittest.TestSuite(tests=())
A test suite is a composite test consisting of a number of TestCases.
Methods & Attributes
TestSuite.addTest(self, test)—TestSuite.addTestmethod/property.TestSuite.addTests(self, tests)—TestSuite.addTestsmethod/property.TestSuite.countTestCases(self)—TestSuite.countTestCasesmethod/property.TestSuite.debug(self)— Run the tests without collecting errors in a TestResultTestSuite.run(self, result, debug=False)—TestSuite.runmethod/property.
Usage
import unittest
class Sample(unittest.TestCase):
def test_a(self) -> None: self.assertTrue(True)
def test_b(self) -> None: self.assertTrue(True)
suite = unittest.TestSuite([Sample("test_a"), Sample("test_b")])
res = unittest.TestResult()
suite.run(res)
assert res.testsRun == 2 and res.wasSuccessful()
Gotchas
- Prefer
TestLoaderover building suites by hand: ManualTestSuitelists are easy to forget to update when new tests are added.
REPL Inspect
from unittest import TestSuite
help(TestSuite)
Linked from
Related notes
- tuts/python3/stdlib_module/unittest/TestResult Linked here; links to this page; shared tags: #stdlib, #unittest
- tuts/python3/stdlib_module/unittest/TextTestResult Linked here; links to this page; shared tags: #stdlib, #unittest
- tuts/python3/stdlib_module/unittest Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/unittest/addModuleCleanup Linked here; shared tags: #stdlib, #unittest
- tuts/python3/stdlib_module/unittest/doModuleCleanups Linked here; shared tags: #stdlib, #unittest
- tuts/python3/stdlib_module/unittest/enterModuleContext Linked here; shared tags: #stdlib, #unittest
- tuts/python3/stdlib_module/unittest/expectedFailure Linked here; shared tags: #stdlib, #unittest
- tuts/python3/stdlib_module/unittest/FunctionTestCase shared tags: #stdlib, #unittest
- tuts/python3/stdlib_module/unittest/installHandler shared tags: #stdlib, #unittest
- tuts/python3/stdlib_module/unittest/IsolatedAsyncioTestCase shared tags: #stdlib, #unittest