← Back to team overview

testtools-dev team mailing list archive

[Merge] lp:~jml/testtools/tag-leakage into lp:testtools

 

Jonathan Lange has proposed merging lp:~jml/testtools/tag-leakage into lp:testtools.

Requested reviews:
  testtools committers (testtools-committers)
Related bugs:
  Bug #985613 in testtools: "ThreadsafeForwardingResult leaks tags"
  https://bugs.launchpad.net/testtools/+bug/985613

For more details, see:
https://code.launchpad.net/~jml/testtools/tag-leakage/+merge/102688

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.
-- 
https://code.launchpad.net/~jml/testtools/tag-leakage/+merge/102688
Your team testtools developers is subscribed to branch lp:testtools.
=== modified file 'testtools/testresult/real.py'
--- testtools/testresult/real.py	2012-04-17 14:34:38 +0000
+++ testtools/testresult/real.py	2012-04-19 12:18:20 +0000
@@ -407,6 +407,7 @@
                 self.result.time(now)
                 if self._any_tags(self._test_tags):
                     self.result.tags(*self._test_tags)
+                    self._test_tags = set(), set()
                 try:
                     method(test, *args, **kwargs)
                 finally:

=== modified file 'testtools/tests/test_testresult.py'
--- testtools/tests/test_testresult.py	2012-04-17 14:34:38 +0000
+++ testtools/tests/test_testresult.py	2012-04-19 12:18:20 +0000
@@ -17,6 +17,7 @@
 from testtools import (
     ExtendedToOriginalDecorator,
     MultiTestResult,
+    PlaceHolder,
     Tagger,
     TestCase,
     TestResult,
@@ -858,6 +859,36 @@
              ('stopTest', self),
              ], events)
 
+    def test_local_tags_dont_leak(self):
+        # A tag set during a test is local to that test and is not set during
+        # the tests that follow.
+        [result], events = self.make_results(1)
+        a, b = PlaceHolder('a'), PlaceHolder('b')
+        result.time(1)
+        result.startTest(a)
+        result.tags(set(['foo']), set([]))
+        result.time(2)
+        result.addSuccess(a)
+        result.stopTest(a)
+        result.time(3)
+        result.startTest(b)
+        result.time(4)
+        result.addSuccess(b)
+        result.stopTest(b)
+        self.assertEqual(
+            [('time', 1),
+             ('startTest', a),
+             ('time', 2),
+             ('tags', set(['foo']), set()),
+             ('addSuccess', a),
+             ('stopTest', a),
+             ('time', 3),
+             ('startTest', b),
+             ('time', 4),
+             ('addSuccess', b),
+             ('stopTest', b),
+             ], events)
+
     def test_startTestRun(self):
         # Calls to startTestRun are not batched, because we are only
         # interested in sending tests atomically, not the whole run.


Follow ups