diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-03-20 20:16:47 +0100 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-03-20 20:16:47 +0100 |
commit | c9b3ef2df06818f055e555c1d23e3ff2d5bf2d74 (patch) | |
tree | e157db4bfab86a28530fb2a4ea77c075003f98aa /Lib/unittest/result.py | |
parent | a612176c9c0c82138e797c2abadb6ef65e97b44a (diff) | |
download | cpython-git-c9b3ef2df06818f055e555c1d23e3ff2d5bf2d74.tar.gz |
Issue #16997: unittest.TestCase now provides a subTest() context manager to procedurally generate, in an easy way, small test instances.
Diffstat (limited to 'Lib/unittest/result.py')
-rw-r--r-- | Lib/unittest/result.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/unittest/result.py b/Lib/unittest/result.py index 97e5426927..eec4f21173 100644 --- a/Lib/unittest/result.py +++ b/Lib/unittest/result.py @@ -121,6 +121,22 @@ class TestResult(object): self.failures.append((test, self._exc_info_to_string(err, test))) self._mirrorOutput = True + @failfast + def addSubTest(self, test, subtest, err): + """Called at the end of a subtest. + 'err' is None if the subtest ended successfully, otherwise it's a + tuple of values as returned by sys.exc_info(). + """ + # By default, we don't do anything with successful subtests, but + # more sophisticated test results might want to record them. + if err is not None: + if issubclass(err[0], test.failureException): + errors = self.failures + else: + errors = self.errors + errors.append((test, self._exc_info_to_string(err, test))) + self._mirrorOutput = True + def addSuccess(self, test): "Called when a test has completed successfully" pass |