On this page
unittest.TextTestRunner
Prev: unittest.TextTestResult | Up: unittest
Rel: unittest.addModuleCleanup, unittest.doModuleCleanups, unittest.enterModuleContext, unittest.expectedFailure
Ref: docs.python.org โ unittest.TextTestRunner
Tags: #public #python3 #stdlib #unittest
Import
import unittest
from unittest import TextTestRunner
Signature & Overview
unittest.TextTestRunner(stream=None, descriptions=True, verbosity=1, failfast=False, buffer=False, resultclass=None, warnings=None, *, tb_locals=False, durations=None)
A test runner class that displays results in textual form.
Methods & Attributes
TextTestRunner.resultclass(stream, descriptions, verbosity, *, durations=None)โ A test result class that can print formatted text results to a stream.TextTestRunner.run(self, test)โ Run the given test case or test suite.
Usage
import io
import unittest
class Sample(unittest.TestCase):
def test_ok(self) -> None: self.assertEqual(3, 3)
buf = io.StringIO()
suite = unittest.defaultTestLoader.loadTestsFromTestCase(Sample)
result = unittest.TextTestRunner(stream=buf, verbosity=2).run(suite)
assert result.wasSuccessful() and "OK" in buf.getvalue()
Gotchas
- Pass
failfast=Trueduring debugging: Stops immediately on the first failure or error instead of running the whole suite.
REPL Inspect
from unittest import TextTestRunner
help(TextTestRunner)
Linked from
Related notes
- 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
- tuts/python3/stdlib_module/unittest/main shared tags: #stdlib, #unittest