← Back to team overview

testtools-dev team mailing list archive

[Merge] lp:~jml/testtools/return-from-multitestresult into lp:testtools

 

Jonathan Lange has proposed merging lp:~jml/testtools/return-from-multitestresult into lp:testtools.

Requested reviews:
  testtools developers (testtools-dev)


Tweaks MultiTestResult to return what it gets from the methods it dispatches to. I made the patch after seeing some code in testrepository that could have used it.

-- 
https://code.launchpad.net/~jml/testtools/return-from-multitestresult/+merge/31829
Your team testtools developers is requested to review the proposed merge of lp:~jml/testtools/return-from-multitestresult into lp:testtools.
=== modified file 'NEWS'
--- NEWS	2010-08-04 13:07:42 +0000
+++ NEWS	2010-08-05 09:54:52 +0000
@@ -19,6 +19,9 @@
  * TestCase now has a 'patch()' method to make it easier to monkey-patching
    objects in tests. See the manual for more information. Fixes bug #310770.
 
+ * MultiTestResult methods now pass back return values from the results it
+   forwards to.
+
 0.9.5
 ~~~~~
 

=== modified file 'testtools/testresult/real.py'
--- testtools/testresult/real.py	2010-07-19 17:37:46 +0000
+++ testtools/testresult/real.py	2010-08-05 09:54:52 +0000
@@ -184,41 +184,43 @@
         self._results = map(ExtendedToOriginalDecorator, results)
 
     def _dispatch(self, message, *args, **kwargs):
-        for result in self._results:
+        return tuple(
             getattr(result, message)(*args, **kwargs)
+            for result in self._results)
 
     def startTest(self, test):
-        self._dispatch('startTest', test)
+        return self._dispatch('startTest', test)
 
     def stopTest(self, test):
-        self._dispatch('stopTest', test)
+        return self._dispatch('stopTest', test)
 
     def addError(self, test, error=None, details=None):
-        self._dispatch('addError', test, error, details=details)
+        return self._dispatch('addError', test, error, details=details)
 
     def addExpectedFailure(self, test, err=None, details=None):
-        self._dispatch('addExpectedFailure', test, err, details=details)
+        return self._dispatch(
+            'addExpectedFailure', test, err, details=details)
 
     def addFailure(self, test, err=None, details=None):
-        self._dispatch('addFailure', test, err, details=details)
+        return self._dispatch('addFailure', test, err, details=details)
 
     def addSkip(self, test, reason=None, details=None):
-        self._dispatch('addSkip', test, reason, details=details)
+        return self._dispatch('addSkip', test, reason, details=details)
 
     def addSuccess(self, test, details=None):
-        self._dispatch('addSuccess', test, details=details)
+        return self._dispatch('addSuccess', test, details=details)
 
     def addUnexpectedSuccess(self, test, details=None):
-        self._dispatch('addUnexpectedSuccess', test, details=details)
+        return self._dispatch('addUnexpectedSuccess', test, details=details)
 
     def startTestRun(self):
-        self._dispatch('startTestRun')
+        return self._dispatch('startTestRun')
 
     def stopTestRun(self):
-        self._dispatch('stopTestRun')
+        return self._dispatch('stopTestRun')
 
     def done(self):
-        self._dispatch('done')
+        return self._dispatch('done')
 
 
 class TextTestResult(TestResult):

=== modified file 'testtools/tests/test_testresult.py'
--- testtools/tests/test_testresult.py	2010-07-29 18:20:54 +0000
+++ testtools/tests/test_testresult.py	2010-08-05 09:54:52 +0000
@@ -264,6 +264,17 @@
         self.multiResult.stopTestRun()
         self.assertResultLogsEqual([('stopTestRun')])
 
+    def test_stopTestRun_returns_results(self):
+        # `MultiTestResult.stopTestRun` returns a tuple of all of the return
+        # values the `stopTestRun`s that it forwards to.
+        class Result(LoggingResult):
+            def stopTestRun(self):
+                super(Result, self).stopTestRun()
+                return 'foo'
+        multi_result = MultiTestResult(Result([]), Result([]))
+        result = multi_result.stopTestRun()
+        self.assertEqual(('foo', 'foo'), result)
+
 
 class TestTextTestResult(TestCase):
     """Tests for `TextTestResult`."""


Follow ups