Merge lp:~lifeless/testtools/bug-812793 into lp:~testtools-committers/testtools/trunk

Proposed by Robert Collins
Status: Merged
Approved by: Jonathan Lange
Approved revision: 305
Merged at revision: 305
Proposed branch: lp:~lifeless/testtools/bug-812793
Merge into: lp:~testtools-committers/testtools/trunk
Diff against target: 71 lines (+29/-4)
3 files modified
NEWS (+7/-0)
testtools/testcase.py (+6/-3)
testtools/tests/test_testcase.py (+16/-1)
To merge this branch: bzr merge lp:~lifeless/testtools/bug-812793
Reviewer Review Type Date Requested Status
Jonathan Lange Approve
Review via email: mp+143860@code.launchpad.net

Description of the change

Minor tweak, should be self evident.

To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :

The code change is indeed self-evident and good. Thanks.

This might have unintended consequences. _details_to_str treats the 'traceback' detail specially, rendering it not so much as a detail but as a traditional test traceback. With this change, if a fixture has a detail named 'traceback', that will be rendered as the main error. This could be confusing to users.

On balance, I'm OK with this patch landing, but would be much happier if we could resolve (or at least document) that potential source of confusion.

(Note: I think the _details_to_str special casing of 'traceback' is a bit of a kludge and would be glad to see it go.)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2013-01-18 09:17:19 +0000
3+++ NEWS 2013-01-18 11:27:25 +0000
4@@ -17,6 +17,13 @@
5 * Testtools now uses setuptools rather than distutils so that we can document
6 the extras dependency. (Robert Collins)
7
8+Improvements
9+------------
10+
11+* Testtools will no longer override test code registered details called
12+ 'traceback' when reporting caught exceptions from test code.
13+ (Robert Collins, #812793)
14+
15 0.9.24
16 ~~~~~~
17
18
19=== modified file 'testtools/testcase.py'
20--- testtools/testcase.py 2013-01-18 09:17:19 +0000
21+++ testtools/testcase.py 2013-01-18 11:27:25 +0000
22@@ -506,9 +506,12 @@
23 def _report_traceback(self, exc_info, tb_label='traceback'):
24 id_gen = self._traceback_id_gens.setdefault(
25 tb_label, itertools.count(0))
26- tb_id = advance_iterator(id_gen)
27- if tb_id:
28- tb_label = '%s-%d' % (tb_label, tb_id)
29+ while True:
30+ tb_id = advance_iterator(id_gen)
31+ if tb_id:
32+ tb_label = '%s-%d' % (tb_label, tb_id)
33+ if tb_label not in self.getDetails():
34+ break
35 self.addDetail(tb_label, content.TracebackContent(exc_info, self))
36
37 @staticmethod
38
39=== modified file 'testtools/tests/test_testcase.py'
40--- testtools/tests/test_testcase.py 2012-07-27 18:53:44 +0000
41+++ testtools/tests/test_testcase.py 2013-01-18 11:27:25 +0000
42@@ -23,7 +23,10 @@
43 _b,
44 _u,
45 )
46-from testtools.content import TracebackContent
47+from testtools.content import (
48+ text_content,
49+ TracebackContent,
50+ )
51 from testtools.matchers import (
52 Annotate,
53 DocTestMatches,
54@@ -609,6 +612,18 @@
55 self.assertFails(expected_error, self.assertIsNotNone, None)
56
57
58+ def test_fail_preserves_traceback_detail(self):
59+ class Test(TestCase):
60+ def test(self):
61+ self.addDetail('traceback', text_content('foo'))
62+ self.fail('bar')
63+ test = Test('test')
64+ result = ExtendedTestResult()
65+ test.run(result)
66+ self.assertEqual(set(['traceback', 'traceback-1']),
67+ set(result._events[1][2].keys()))
68+
69+
70 class TestAddCleanup(TestCase):
71 """Tests for TestCase.addCleanup."""
72

Subscribers

People subscribed via source and target branches