Merge lp:~jml/testtools/tag-leakage into lp:~testtools-committers/testtools/trunk

Proposed by Jonathan Lange
Status: Merged
Merged at revision: 254
Proposed branch: lp:~jml/testtools/tag-leakage
Merge into: lp:~testtools-committers/testtools/trunk
Diff against target: 60 lines (+32/-0)
2 files modified
testtools/testresult/real.py (+1/-0)
testtools/tests/test_testresult.py (+31/-0)
To merge this branch: bzr merge lp:~jml/testtools/tag-leakage
Reviewer Review Type Date Requested Status
Jonathan Lange Approve
Review via email: mp+102688@code.launchpad.net

Description of the change

As reported in https://code.launchpad.net/~benji/testrepository/add-worker-id-tagging/+merge/102574, ThreadsafeForwardingResult leaks tags. This fixes the issue by resetting _test_tags after forwarding the tags therein.

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

https://code.launchpad.net/~jml/testrepository/tag-leakage/ shows the steps taken to isolate the bug.

Revision history for this message
Jonathan Lange (jml) wrote :

Merging without review since the substantive change is quite small. Post-merge reviews most welcome.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'testtools/testresult/real.py'
2--- testtools/testresult/real.py 2012-04-17 14:34:38 +0000
3+++ testtools/testresult/real.py 2012-04-19 12:18:20 +0000
4@@ -407,6 +407,7 @@
5 self.result.time(now)
6 if self._any_tags(self._test_tags):
7 self.result.tags(*self._test_tags)
8+ self._test_tags = set(), set()
9 try:
10 method(test, *args, **kwargs)
11 finally:
12
13=== modified file 'testtools/tests/test_testresult.py'
14--- testtools/tests/test_testresult.py 2012-04-17 14:34:38 +0000
15+++ testtools/tests/test_testresult.py 2012-04-19 12:18:20 +0000
16@@ -17,6 +17,7 @@
17 from testtools import (
18 ExtendedToOriginalDecorator,
19 MultiTestResult,
20+ PlaceHolder,
21 Tagger,
22 TestCase,
23 TestResult,
24@@ -858,6 +859,36 @@
25 ('stopTest', self),
26 ], events)
27
28+ def test_local_tags_dont_leak(self):
29+ # A tag set during a test is local to that test and is not set during
30+ # the tests that follow.
31+ [result], events = self.make_results(1)
32+ a, b = PlaceHolder('a'), PlaceHolder('b')
33+ result.time(1)
34+ result.startTest(a)
35+ result.tags(set(['foo']), set([]))
36+ result.time(2)
37+ result.addSuccess(a)
38+ result.stopTest(a)
39+ result.time(3)
40+ result.startTest(b)
41+ result.time(4)
42+ result.addSuccess(b)
43+ result.stopTest(b)
44+ self.assertEqual(
45+ [('time', 1),
46+ ('startTest', a),
47+ ('time', 2),
48+ ('tags', set(['foo']), set()),
49+ ('addSuccess', a),
50+ ('stopTest', a),
51+ ('time', 3),
52+ ('startTest', b),
53+ ('time', 4),
54+ ('addSuccess', b),
55+ ('stopTest', b),
56+ ], events)
57+
58 def test_startTestRun(self):
59 # Calls to startTestRun are not batched, because we are only
60 # interested in sending tests atomically, not the whole run.

Subscribers

People subscribed via source and target branches