mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
Issue #10979. unittest stdout buffering now works with class and module setup and teardown.
This commit is contained in:
parent
b2760a0bc5
commit
42ec7cb105
4 changed files with 94 additions and 2 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue