← Back to team overview

testtools-dev team mailing list archive

[Merge] lp:~lifeless/testtools/bug-812793 into lp:testtools

 

Robert Collins has proposed merging lp:~lifeless/testtools/bug-812793 into lp:testtools.

Requested reviews:
  testtools committers (testtools-committers)
Related bugs:
  Bug #812793 in testtools: "Failures and errors mask explicitly added details named 'traceback'"
  https://bugs.launchpad.net/testtools/+bug/812793

For more details, see:
https://code.launchpad.net/~lifeless/testtools/bug-812793/+merge/143860

Minor tweak, should be self evident.
-- 
https://code.launchpad.net/~lifeless/testtools/bug-812793/+merge/143860
Your team testtools developers is subscribed to branch lp:testtools.
=== modified file 'NEWS'
--- NEWS	2013-01-18 09:17:19 +0000
+++ NEWS	2013-01-18 11:27:25 +0000
@@ -17,6 +17,13 @@
 * Testtools now uses setuptools rather than distutils so that we can document
   the extras dependency. (Robert Collins)
 
+Improvements
+------------
+
+* Testtools will no longer override test code registered details called
+  'traceback' when reporting caught exceptions from test code.
+  (Robert Collins, #812793)
+
 0.9.24
 ~~~~~~
 

=== modified file 'testtools/testcase.py'
--- testtools/testcase.py	2013-01-18 09:17:19 +0000
+++ testtools/testcase.py	2013-01-18 11:27:25 +0000
@@ -506,9 +506,12 @@
     def _report_traceback(self, exc_info, tb_label='traceback'):
         id_gen = self._traceback_id_gens.setdefault(
             tb_label, itertools.count(0))
-        tb_id = advance_iterator(id_gen)
-        if tb_id:
-            tb_label = '%s-%d' % (tb_label, tb_id)
+        while True:
+            tb_id = advance_iterator(id_gen)
+            if tb_id:
+                tb_label = '%s-%d' % (tb_label, tb_id)
+            if tb_label not in self.getDetails():
+                break
         self.addDetail(tb_label, content.TracebackContent(exc_info, self))
 
     @staticmethod

=== modified file 'testtools/tests/test_testcase.py'
--- testtools/tests/test_testcase.py	2012-07-27 18:53:44 +0000
+++ testtools/tests/test_testcase.py	2013-01-18 11:27:25 +0000
@@ -23,7 +23,10 @@
     _b,
     _u,
     )
-from testtools.content import TracebackContent
+from testtools.content import (
+    text_content,
+    TracebackContent,
+    )
 from testtools.matchers import (
     Annotate,
     DocTestMatches,
@@ -609,6 +612,18 @@
         self.assertFails(expected_error, self.assertIsNotNone, None)
 
 
+    def test_fail_preserves_traceback_detail(self):
+        class Test(TestCase):
+            def test(self):
+                self.addDetail('traceback', text_content('foo'))
+                self.fail('bar')
+        test = Test('test')
+        result = ExtendedTestResult()
+        test.run(result)
+        self.assertEqual(set(['traceback', 'traceback-1']),
+            set(result._events[1][2].keys()))
+
+
 class TestAddCleanup(TestCase):
     """Tests for TestCase.addCleanup."""
 


Follow ups