diff options
author | Michael Foord <michael@python.org> | 2011-03-17 17:44:18 (GMT) |
---|---|---|
committer | Michael Foord <michael@python.org> | 2011-03-17 17:44:18 (GMT) |
commit | 42ec7cb1050c5d1bdf5d504903fabe8bb372b5da (patch) | |
tree | 6cb48e730f65fb53688baef5dac66a8bed95538f /Lib/unittest/result.py | |
parent | b2760a0bc5166f61180e5ed7e25bcf4132c68e62 (diff) | |
download | cpython-42ec7cb1050c5d1bdf5d504903fabe8bb372b5da.zip cpython-42ec7cb1050c5d1bdf5d504903fabe8bb372b5da.tar.gz cpython-42ec7cb1050c5d1bdf5d504903fabe8bb372b5da.tar.bz2 |
Issue #10979. unittest stdout buffering now works with class and module setup and teardown.
Diffstat (limited to 'Lib/unittest/result.py')
-rw-r--r-- | Lib/unittest/result.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/unittest/result.py b/Lib/unittest/result.py index 3dc7154..44bf186 100644 --- a/Lib/unittest/result.py +++ b/Lib/unittest/result.py @@ -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. |