summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-04-02 22:08:29 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-04-02 22:08:29 (GMT)
commit58c1e788067a79e89d6f5c34a5da312525bf322b (patch)
tree10a7c46327b60646a165857ab473eaa4aaf5b95b /Lib
parent19479fa4375c4ba7166e66f2cdb73ff570cdbb56 (diff)
downloadcpython-58c1e788067a79e89d6f5c34a5da312525bf322b.zip
cpython-58c1e788067a79e89d6f5c34a5da312525bf322b.tar.gz
cpython-58c1e788067a79e89d6f5c34a5da312525bf322b.tar.bz2
TestResult stores original sys.stdout and tests no longer use sys.__stdout__ (etc) in tests for unittest -b command line option
Diffstat (limited to 'Lib')
-rw-r--r--Lib/unittest/result.py6
-rw-r--r--Lib/unittest/test/test_result.py31
2 files changed, 18 insertions, 19 deletions
diff --git a/Lib/unittest/result.py b/Lib/unittest/result.py
index 46eba04..cb6d41c 100644
--- a/Lib/unittest/result.py
+++ b/Lib/unittest/result.py
@@ -53,6 +53,8 @@ class TestResult(object):
self.buffer = False
self._stdout_buffer = StringIO()
self._stderr_buffer = StringIO()
+ self._original_stdout = sys.stdout
+ self._original_stderr = sys.stderr
self._mirrorOutput = False
def printErrors(self):
@@ -81,11 +83,11 @@ class TestResult(object):
if output:
if not output.endswith(NEWLINE):
output += NEWLINE
- sys.__stdout__.write(STDOUT_LINE % output)
+ self._original_stdout.write(STDOUT_LINE % output)
if error:
if not error.endswith(NEWLINE):
error += NEWLINE
- sys.__stderr__.write(STDERR_LINE % error)
+ self._original_stderr.write(STDERR_LINE % error)
sys.stdout = _std_out
sys.stderr = _std_err
diff --git a/Lib/unittest/test/test_result.py b/Lib/unittest/test/test_result.py
index 8637679..c483c7d 100644
--- a/Lib/unittest/test/test_result.py
+++ b/Lib/unittest/test/test_result.py
@@ -362,12 +362,12 @@ class Test_OldTestResult(unittest.TestCase):
class TestOutputBuffering(unittest.TestCase):
def setUp(self):
- self._real_out = sys.__stdout__
- self._real_err = sys.__stderr__
+ self._real_out = sys.stdout
+ self._real_err = sys.stderr
def tearDown(self):
- sys.stdout = sys.__stdout__ = self._real_out
- sys.stderr = sys.__stderr__ = self._real_err
+ sys.stdout = self._real_out
+ sys.stderr = self._real_err
def testBufferOutputOff(self):
real_out = self._real_out
@@ -407,8 +407,8 @@ class TestOutputBuffering(unittest.TestCase):
out_stream = sys.stdout
err_stream = sys.stderr
- sys.__stdout__ = StringIO()
- sys.__stderr__ = StringIO()
+ result._original_stdout = StringIO()
+ result._original_stderr = StringIO()
print 'foo'
print >> sys.stderr, 'bar'
@@ -416,8 +416,8 @@ class TestOutputBuffering(unittest.TestCase):
self.assertEqual(out_stream.getvalue(), 'foo\n')
self.assertEqual(err_stream.getvalue(), 'bar\n')
- self.assertEqual(sys.__stdout__.getvalue(), '')
- self.assertEqual(sys.__stderr__.getvalue(), '')
+ self.assertEqual(result._original_stdout.getvalue(), '')
+ self.assertEqual(result._original_stderr.getvalue(), '')
result.addSuccess(self)
result.stopTest(self)
@@ -425,8 +425,8 @@ class TestOutputBuffering(unittest.TestCase):
self.assertIs(real_out, sys.stdout)
self.assertIs(real_err, sys.stderr)
- self.assertEqual(sys.__stdout__.getvalue(), '')
- self.assertEqual(sys.__stderr__.getvalue(), '')
+ self.assertEqual(result._original_stdout.getvalue(), '')
+ self.assertEqual(result._original_stderr.getvalue(), '')
self.assertEqual(out_stream.getvalue(), '')
self.assertEqual(err_stream.getvalue(), '')
@@ -439,20 +439,17 @@ class TestOutputBuffering(unittest.TestCase):
return result
def testBufferOutputAddErrorOrFailure(self):
- def clear():
- sys.__stdout__ = StringIO()
- sys.__stderr__ = StringIO()
-
for message_attr, add_attr, include_error in [
('errors', 'addError', True),
('failures', 'addFailure', False),
('errors', 'addError', True),
('failures', 'addFailure', False)
]:
- clear()
result = self.getStartedResult()
buffered_out = sys.stdout
buffered_err = sys.stderr
+ result._original_stdout = StringIO()
+ result._original_stderr = StringIO()
print >> sys.stdout, 'foo'
if include_error:
@@ -480,8 +477,8 @@ class TestOutputBuffering(unittest.TestCase):
expectedFullMessage = 'None\n%s%s' % (expectedOutMessage, expectedErrMessage)
self.assertIs(test, self)
- self.assertEqual(sys.__stdout__.getvalue(), expectedOutMessage)
- self.assertEqual(sys.__stderr__.getvalue(), expectedErrMessage)
+ self.assertEqual(result._original_stdout.getvalue(), expectedOutMessage)
+ self.assertEqual(result._original_stderr.getvalue(), expectedErrMessage)
self.assertMultiLineEqual(message, expectedFullMessage)
if __name__ == '__main__':