Fix issue 9926. TestSuite subclasses that override __call__ are called correctly.
diff --git a/Lib/unittest/suite.py b/Lib/unittest/suite.py
index b6ae68c..73f0e17 100644
--- a/Lib/unittest/suite.py
+++ b/Lib/unittest/suite.py
@@ -77,23 +77,11 @@
subclassing, do not forget to call the base class constructor.
"""
+ def run(self, result, debug=False):
+ topLevel = False
+ if getattr(result, '_testRunEntered', False) is False:
+ result._testRunEntered = topLevel = True
- def run(self, result):
- self._wrapped_run(result)
- self._tearDownPreviousClass(None, result)
- self._handleModuleTearDown(result)
- return result
-
- def debug(self):
- """Run the tests without collecting errors in a TestResult"""
- debug = _DebugResult()
- self._wrapped_run(debug, True)
- self._tearDownPreviousClass(None, debug)
- self._handleModuleTearDown(debug)
-
- ################################
- # private methods
- def _wrapped_run(self, result, debug=False):
for test in self:
if result.shouldStop:
break
@@ -108,13 +96,23 @@
getattr(result, '_moduleSetUpFailed', False)):
continue
- if hasattr(test, '_wrapped_run'):
- test._wrapped_run(result, debug)
- elif not debug:
+ if not debug:
test(result)
else:
test.debug()
+ if topLevel:
+ self._tearDownPreviousClass(None, result)
+ self._handleModuleTearDown(result)
+ return result
+
+ def debug(self):
+ """Run the tests without collecting errors in a TestResult"""
+ debug = _DebugResult()
+ self.run(debug, True)
+
+ ################################
+
def _handleClassSetUp(self, test, result):
previousClass = getattr(result, '_previousTestClass', None)
currentClass = test.__class__