Merge return-from-multitestresult.

This commit is contained in:
Jonathan Lange
2010-08-05 11:19:28 +01:00
3 changed files with 28 additions and 12 deletions

3
NEWS
View File

@@ -22,6 +22,9 @@ Improvements
* 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
~~~~~

View File

@@ -184,41 +184,43 @@ class MultiTestResult(TestResult):
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):

View File

@@ -264,6 +264,17 @@ class TestMultiTestResult(TestWithFakeExceptions):
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`."""