Commit d23ea061 authored by Michael Foord's avatar Michael Foord

Merged revisions 80708 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r80708 | michael.foord | 2010-05-02 21:39:42 +0100 (Sun, 02 May 2010) | 1 line

  Fix unittest tests to not abuse traceback.format_exception
........
parent 6e20a1bd
...@@ -153,9 +153,7 @@ class TestResult(object): ...@@ -153,9 +153,7 @@ class TestResult(object):
length = self._count_relevant_tb_levels(tb) length = self._count_relevant_tb_levels(tb)
msgLines = traceback.format_exception(exctype, value, tb, length) msgLines = traceback.format_exception(exctype, value, tb, length)
else: else:
chain = exctype is not None msgLines = traceback.format_exception(exctype, value, tb)
msgLines = traceback.format_exception(exctype, value, tb,
chain=chain)
if self.buffer: if self.buffer:
output = sys.stdout.getvalue() output = sys.stdout.getvalue()
......
...@@ -4,6 +4,7 @@ import textwrap ...@@ -4,6 +4,7 @@ import textwrap
from test import support from test import support
import traceback
import unittest import unittest
...@@ -361,6 +362,15 @@ class Test_OldTestResult(unittest.TestCase): ...@@ -361,6 +362,15 @@ class Test_OldTestResult(unittest.TestCase):
runner.run(Test('testFoo')) runner.run(Test('testFoo'))
class MockTraceback(object):
@staticmethod
def format_exception(*_):
return ['A traceback']
def restore_traceback():
unittest.result.traceback = traceback
class TestOutputBuffering(unittest.TestCase): class TestOutputBuffering(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -441,6 +451,9 @@ class TestOutputBuffering(unittest.TestCase): ...@@ -441,6 +451,9 @@ class TestOutputBuffering(unittest.TestCase):
return result return result
def testBufferOutputAddErrorOrFailure(self): def testBufferOutputAddErrorOrFailure(self):
unittest.result.traceback = MockTraceback
self.addCleanup(restore_traceback)
for message_attr, add_attr, include_error in [ for message_attr, add_attr, include_error in [
('errors', 'addError', True), ('errors', 'addError', True),
('failures', 'addFailure', False), ('failures', 'addFailure', False),
...@@ -476,7 +489,8 @@ class TestOutputBuffering(unittest.TestCase): ...@@ -476,7 +489,8 @@ class TestOutputBuffering(unittest.TestCase):
Stderr: Stderr:
bar bar
""") """)
expectedFullMessage = 'NoneType\n%s%s' % (expectedOutMessage, expectedErrMessage)
expectedFullMessage = 'A traceback%s%s' % (expectedOutMessage, expectedErrMessage)
self.assertIs(test, self) self.assertIs(test, self)
self.assertEqual(result._original_stdout.getvalue(), expectedOutMessage) self.assertEqual(result._original_stdout.getvalue(), expectedOutMessage)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment