On this page
unittest.TestResult
Prev: unittest.TestLoader | Up: unittest | Next: unittest.TestSuite
Rel: unittest.addModuleCleanup, unittest.doModuleCleanups, unittest.enterModuleContext, unittest.expectedFailure
Ref: docs.python.org — unittest.TestResult
Tags: #public #python3 #stdlib #unittest
Import
import unittest
from unittest import TestResult
Signature & Overview
unittest.TestResult(stream=None, descriptions=None, verbosity=None)
Holder for test result information.
Methods & Attributes
TestResult.addDuration(self, test, elapsed)— Called when a test finished to run, regardless of its outcome.TestResult.addError(self, test, err)— Called when an error has occurred. 'err' is a tuple of values as returned by sys.exc_info().TestResult.addExpectedFailure(self, test, err)— Called when an expected failure/error occurred.TestResult.addFailure(self, test, err)— Called when an error has occurred. 'err' is a tuple of values as returned by sys.exc_info().TestResult.addSkip(self, test, reason)— Called when a test is skipped.TestResult.addSubTest(self, test, subtest, err)— Called at the end of a subtest.TestResult.addSuccess(self, test)— Called when a test has completed successfullyTestResult.addUnexpectedSuccess(self, test)— Called when a test was expected to fail, but succeed.TestResult.printErrors(self)— Called by TestRunner after test runTestResult.startTest(self, test)— Called when the given test is about to be runTestResult.startTestRun(self)— Called once before any tests are executed.TestResult.stop(self)— Indicates that the tests should be aborted.TestResult.stopTest(self, test)— Called when the given test has been runTestResult.stopTestRun(self)— Called once after all tests are executed.TestResult.wasSuccessful(self)— Tells whether or not this result was a success.
Usage
import unittest
class Sample(unittest.TestCase):
def test_pass(self) -> None:
self.assertEqual(1, 1)
res = unittest.TestResult()
Sample("test_pass").run(res)
assert res.wasSuccessful() and res.testsRun == 1 and res.failures == []
Gotchas
- Programmatic outcome container: Inspect
.testsRun,.failures,.errors,.skipped, and.wasSuccessful().
REPL Inspect
from unittest import TestResult
help(TestResult)
Linked from
Related notes
- tuts/python3/stdlib_module/unittest/TestLoader Linked here; links to this page; shared tags: #stdlib, #unittest
- tuts/python3/stdlib_module/unittest/TestSuite 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