Rev 4658: Push all starting up reporting down into startTestRun. in http://bazaar.launchpad.net/~lifeless/bzr/test-speed

Robert Collins robertc at robertcollins.net
Thu Aug 27 00:25:31 BST 2009


At http://bazaar.launchpad.net/~lifeless/bzr/test-speed

------------------------------------------------------------
revno: 4658
revision-id: robertc at robertcollins.net-20090826232528-sld5o6xa1afm08y8
parent: robertc at robertcollins.net-20090826231441-8ouomxwxzgxt180l
committer: Robert Collins <robertc at robertcollins.net>
branch nick: test-speed
timestamp: Thu 2009-08-27 09:25:28 +1000
message:
  Push all starting up reporting down into startTestRun.
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-08-26 23:14:41 +0000
+++ b/bzrlib/tests/__init__.py	2009-08-26 23:25:28 +0000
@@ -416,7 +416,7 @@
     def report_cleaning_up(self):
         pass
 
-    def report_starting(self):
+    def startTestRun(self):
         self.startTime = time.time()
 
     def report_success(self, test):
@@ -457,8 +457,8 @@
         self.pb.finished()
         super(TextTestResult, self).stopTestRun()
 
-    def report_starting(self):
-        super(TextTestResult, self).report_starting()
+    def startTestRun(self):
+        super(TextTestResult, self).startTestRun()
         self.pb.update('[test 0/%d] Starting' % (self.num_tests))
 
     def printErrors(self):
@@ -543,8 +543,8 @@
             result = a_string
         return result.ljust(final_width)
 
-    def report_starting(self):
-        super(VerboseTestResult, self).report_starting()
+    def startTestRun(self):
+        super(VerboseTestResult, self).startTestRun()
         self.stream.write('running %d tests...\n' % self.num_tests)
 
     def report_test_start(self, test):
@@ -641,29 +641,34 @@
             result_class = TextTestResult
         elif self.verbosity >= 2:
             result_class = VerboseTestResult
-        result = result_class(self.stream,
+        original_result = result_class(self.stream,
                               self.descriptions,
                               self.verbosity,
                               bench_history=self._bench_history,
                               strict=self._strict,
                               )
-        run_result = result
+        # Signal to result objects that look at stop early policy to stop,
+        original_result.stop_early = self.stop_on_failure
+        result = original_result
         for decorator in self._result_decorators:
-            run_result = decorator(run_result)
-        result.stop_early = self.stop_on_failure
-        result.report_starting()
+            result = decorator(result)
+            result.stop_early = self.stop_on_failure
         try:
             import testtools
         except ImportError:
-            test.run(run_result)
+            pass
         else:
             if isinstance(test, testtools.ConcurrentTestSuite):
                 # We need to catch bzr specific behaviors
-                test.run(BZRTransformingResult(run_result))
-            else:
-                test.run(run_result)
-        run_result.stopTestRun()
-        return result
+                result = BZRTransformingResult(result)
+        result.startTestRun()
+        try:
+            test.run(result)
+        finally:
+            result.stopTestRun()
+        # higher level code uses our extended protocol to determine
+        # what exit code to give.
+        return original_result
 
 
 def iter_suite_tests(suite):

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2009-08-26 23:14:41 +0000
+++ b/bzrlib/tests/test_selftest.py	2009-08-26 23:25:28 +0000
@@ -1294,6 +1294,20 @@
         self.assertContainsRe(log, 'this will be kept')
         self.assertEqual(log, test._log_contents)
 
+    def test_startTestRun(self):
+        """run should call result.startTestRun()"""
+        calls = []
+        class LoggingDecorator(tests.ForwardingResult):
+            def startTestRun(self):
+                tests.ForwardingResult.startTestRun(self)
+                calls.append('startTestRun')
+        test = unittest.FunctionTestCase(lambda:None)
+        stream = StringIO()
+        runner = tests.TextTestRunner(stream=stream,
+            result_decorators=[LoggingDecorator])
+        result = self.run_test_runner(runner, test)
+        self.assertLength(1, calls)
+
     def test_stopTestRun(self):
         """run should call result.stopTestRun()"""
         calls = []




More information about the bazaar-commits mailing list