]> granicus.if.org Git - python/commitdiff
Merged revisions 86101 via svnmerge from
authorMichael Foord <fuzzyman@voidspace.org.uk>
Mon, 1 Nov 2010 22:11:53 +0000 (22:11 +0000)
committerMichael Foord <fuzzyman@voidspace.org.uk>
Mon, 1 Nov 2010 22:11:53 +0000 (22:11 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r86101 | michael.foord | 2010-11-01 21:09:03 +0000 (Mon, 01 Nov 2010) | 1 line

  Fix issue 9926. TestSuite subclasses that override __call__ are called correctly.
........

Lib/unittest/result.py
Lib/unittest/suite.py
Lib/unittest/test/test_suite.py
Misc/NEWS

index 4b7cde658ac2d323008266999a0b52ce7989d832..1f66f1bb18f39c58b8b6da9d758a710653223672 100644 (file)
@@ -35,6 +35,7 @@ class TestResult(object):
     formatted traceback of the error that occurred.
     """
     _previousTestClass = None
+    _testRunEntered = False
     _moduleSetUpFailed = False
     def __init__(self, stream=None, descriptions=None, verbosity=None):
         self.failfast = False
index 8602107eb8b8c9c287a64cba30d062e1ccb4829f..e8fbdc31fed7091711414525dcbd593376dd6de6 100644 (file)
@@ -80,23 +80,11 @@ class TestSuite(BaseTestSuite):
     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
@@ -111,13 +99,23 @@ class TestSuite(BaseTestSuite):
                     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__
index f4a7468e71984058fda3c7f138491048ffbd2b8f..d212bd05dc4e6ab8c1b139329f2e541c7e815b5c 100644 (file)
@@ -345,5 +345,19 @@ class Test_TestSuite(unittest.TestCase, TestEquality):
         self.assertEqual(result.testsRun, 2)
 
 
+    def test_overriding_call(self):
+        class MySuite(unittest.TestSuite):
+            called = False
+            def __call__(self, *args, **kw):
+                self.called = True
+                unittest.TestSuite.__call__(self, *args, **kw)
+
+        suite = MySuite()
+        wrapper = unittest.TestSuite()
+        wrapper.addTest(suite)
+        wrapper(unittest.TestResult())
+        self.assertTrue(suite.called)
+
+
 if __name__ == '__main__':
     unittest.main()
index b9e38e2963d57260306bd8b37a3b2ae52c4a38ca..720ecc12125d61817d64a53c2de6450f837e87b2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -66,6 +66,8 @@ Core and Builtins
 Library
 -------
 
+- Issue 120176: Wrapped TestSuite subclass does not get __call__ executed
+
 - Issue 6706: asyncore accept() method no longer raises EWOULDBLOCK/ECONNABORTED
   on incomplete connection attempt but returns None instead.