mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Issue #16997: unittest.TestCase now provides a subTest() context manager to procedurally generate, in an easy way, small test instances.
This commit is contained in:
parent
a612176c9c
commit
c9b3ef2df0
10 changed files with 540 additions and 106 deletions
|
|
@ -41,7 +41,7 @@ class TestHashing(object):
|
|||
self.fail("Problem hashing %s and %s: %s" % (obj_1, obj_2, e))
|
||||
|
||||
|
||||
class LoggingResult(unittest.TestResult):
|
||||
class _BaseLoggingResult(unittest.TestResult):
|
||||
def __init__(self, log):
|
||||
self._events = log
|
||||
super().__init__()
|
||||
|
|
@ -52,7 +52,7 @@ class LoggingResult(unittest.TestResult):
|
|||
|
||||
def startTestRun(self):
|
||||
self._events.append('startTestRun')
|
||||
super(LoggingResult, self).startTestRun()
|
||||
super().startTestRun()
|
||||
|
||||
def stopTest(self, test):
|
||||
self._events.append('stopTest')
|
||||
|
|
@ -60,7 +60,7 @@ class LoggingResult(unittest.TestResult):
|
|||
|
||||
def stopTestRun(self):
|
||||
self._events.append('stopTestRun')
|
||||
super(LoggingResult, self).stopTestRun()
|
||||
super().stopTestRun()
|
||||
|
||||
def addFailure(self, *args):
|
||||
self._events.append('addFailure')
|
||||
|
|
@ -68,7 +68,7 @@ class LoggingResult(unittest.TestResult):
|
|||
|
||||
def addSuccess(self, *args):
|
||||
self._events.append('addSuccess')
|
||||
super(LoggingResult, self).addSuccess(*args)
|
||||
super().addSuccess(*args)
|
||||
|
||||
def addError(self, *args):
|
||||
self._events.append('addError')
|
||||
|
|
@ -76,15 +76,39 @@ class LoggingResult(unittest.TestResult):
|
|||
|
||||
def addSkip(self, *args):
|
||||
self._events.append('addSkip')
|
||||
super(LoggingResult, self).addSkip(*args)
|
||||
super().addSkip(*args)
|
||||
|
||||
def addExpectedFailure(self, *args):
|
||||
self._events.append('addExpectedFailure')
|
||||
super(LoggingResult, self).addExpectedFailure(*args)
|
||||
super().addExpectedFailure(*args)
|
||||
|
||||
def addUnexpectedSuccess(self, *args):
|
||||
self._events.append('addUnexpectedSuccess')
|
||||
super(LoggingResult, self).addUnexpectedSuccess(*args)
|
||||
super().addUnexpectedSuccess(*args)
|
||||
|
||||
|
||||
class LegacyLoggingResult(_BaseLoggingResult):
|
||||
"""
|
||||
A legacy TestResult implementation, without an addSubTest method,
|
||||
which records its method calls.
|
||||
"""
|
||||
|
||||
@property
|
||||
def addSubTest(self):
|
||||
raise AttributeError
|
||||
|
||||
|
||||
class LoggingResult(_BaseLoggingResult):
|
||||
"""
|
||||
A TestResult implementation which records its method calls.
|
||||
"""
|
||||
|
||||
def addSubTest(self, test, subtest, err):
|
||||
if err is None:
|
||||
self._events.append('addSubTestSuccess')
|
||||
else:
|
||||
self._events.append('addSubTestFailure')
|
||||
super().addSubTest(test, subtest, err)
|
||||
|
||||
|
||||
class ResultWithNoStartTestRunStopTestRun(object):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue