Issue #10979. unittest stdout buffering now works with class and module setup and teardown.

This commit is contained in:
Michael Foord 2011-03-17 13:44:18 -04:00
parent b2760a0bc5
commit 42ec7cb105
4 changed files with 94 additions and 2 deletions

View file

@ -59,6 +59,9 @@ class TestResult(object):
"Called when the given test is about to be run"
self.testsRun += 1
self._mirrorOutput = False
self._setupStdout()
def _setupStdout(self):
if self.buffer:
if self._stderr_buffer is None:
self._stderr_buffer = io.StringIO()
@ -74,6 +77,10 @@ class TestResult(object):
def stopTest(self, test):
"""Called when the given test has been run"""
self._restoreStdout()
self._mirrorOutput = False
def _restoreStdout(self):
if self.buffer:
if self._mirrorOutput:
output = sys.stdout.getvalue()
@ -93,7 +100,6 @@ class TestResult(object):
self._stdout_buffer.truncate()
self._stderr_buffer.seek(0)
self._stderr_buffer.truncate()
self._mirrorOutput = False
def stopTestRun(self):
"""Called once after all tests are executed.