diff --git a/Lib/unittest.py b/Lib/unittest.py
index d5c2927..b2dc320 100644
--- a/Lib/unittest.py
+++ b/Lib/unittest.py
@@ -186,10 +186,22 @@
"Called when the given test is about to be run"
self.testsRun = self.testsRun + 1
+ def startTestRun(self):
+ """Called once before any tests are executed.
+
+ See startTest for a method called before each test.
+ """
+
def stopTest(self, test):
"Called when the given test has been run"
pass
+ def stopTestRun(self):
+ """Called once after all tests are executed.
+
+ See stopTest for a method called after each test.
+ """
+
def addError(self, test, err):
"""Called when an error has occurred. 'err' is a tuple of values as
returned by sys.exc_info().
@@ -437,8 +449,13 @@
(_strclass(self.__class__), self._testMethodName)
def run(self, result=None):
+ orig_result = result
if result is None:
result = self.defaultTestResult()
+ startTestRun = getattr(result, 'startTestRun', None)
+ if startTestRun is not None:
+ startTestRun()
+
self._result = result
result.startTest(self)
testMethod = getattr(self, self._testMethodName)
@@ -478,6 +495,10 @@
result.addSuccess(self)
finally:
result.stopTest(self)
+ if orig_result is None:
+ stopTestRun = getattr(result, 'stopTestRun', None)
+ if stopTestRun is not None:
+ stopTestRun()
def doCleanups(self):
"""Execute all cleanup functions. Normally called for you after
@@ -1433,7 +1454,15 @@
"Run the given test case or test suite."
result = self._makeResult()
startTime = time.time()
- test(result)
+ startTestRun = getattr(result, 'startTestRun', None)
+ if startTestRun is not None:
+ startTestRun()
+ try:
+ test(result)
+ finally:
+ stopTestRun = getattr(result, 'stopTestRun', None)
+ if stopTestRun is not None:
+ stopTestRun()
stopTime = time.time()
timeTaken = stopTime - startTime
result.printErrors()