[Python-checkins] r80708 - python/trunk/Lib/unittest/test/test_result.py

michael.foord python-checkins at python.org
Sun May 2 22:39:42 CEST 2010


Author: michael.foord
Date: Sun May  2 22:39:42 2010
New Revision: 80708

Log:
Fix unittest tests to not abuse traceback.format_exception

Modified:
   python/trunk/Lib/unittest/test/test_result.py

Modified: python/trunk/Lib/unittest/test/test_result.py
==============================================================================
--- python/trunk/Lib/unittest/test/test_result.py	(original)
+++ python/trunk/Lib/unittest/test/test_result.py	Sun May  2 22:39:42 2010
@@ -3,6 +3,7 @@
 from StringIO import StringIO
 from test import test_support
 
+import traceback
 import unittest
 
 
@@ -361,6 +362,15 @@
         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):
 
     def setUp(self):
@@ -441,6 +451,9 @@
         return result
 
     def testBufferOutputAddErrorOrFailure(self):
+        unittest.result.traceback = MockTraceback
+        self.addCleanup(restore_traceback)
+
         for message_attr, add_attr, include_error in [
             ('errors', 'addError', True),
             ('failures', 'addFailure', False),
@@ -476,7 +489,7 @@
                 Stderr:
                 bar
             """)
-            expectedFullMessage = 'None\n%s%s' % (expectedOutMessage, expectedErrMessage)
+            expectedFullMessage = 'A traceback%s%s' % (expectedOutMessage, expectedErrMessage)
 
             self.assertIs(test, self)
             self.assertEqual(result._original_stdout.getvalue(), expectedOutMessage)


More information about the Python-checkins mailing list