Merge lp:~jml/testtools/tagger into lp:~testtools-committers/testtools/trunk

Proposed by Jonathan Lange
Status: Merged
Merged at revision: 253
Proposed branch: lp:~jml/testtools/tagger
Merge into: lp:~testtools-committers/testtools/trunk
Diff against target: 119 lines (+48/-0)
4 files modified
testtools/__init__.py (+2/-0)
testtools/testresult/__init__.py (+2/-0)
testtools/testresult/real.py (+19/-0)
testtools/tests/test_testresult.py (+25/-0)
To merge this branch: bzr merge lp:~jml/testtools/tagger
Reviewer Review Type Date Requested Status
testtools committers Pending
Review via email: mp+101904@code.launchpad.net

Description of the change

When we get tests from multiple sources and want to assemble them into one test result, we want to have some way of identifying which source an individual test came from. Since we can't rely on ordering, a natural way of doing this is to tag each test with some sort of label that identifies its source.

This branch adds a TestResultDecorator that individually tags each test sent through it with a specific set of tags.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'testtools/__init__.py'
2--- testtools/__init__.py 2012-04-13 09:42:40 +0000
3+++ testtools/__init__.py 2012-04-13 12:37:22 +0000
4@@ -14,6 +14,7 @@
5 'MultiTestResult',
6 'PlaceHolder',
7 'run_test_with',
8+ 'Tagger',
9 'TestCase',
10 'TestCommand',
11 'TestByTestResult',
12@@ -57,6 +58,7 @@
13 from testtools.testresult import (
14 ExtendedToOriginalDecorator,
15 MultiTestResult,
16+ Tagger,
17 TestByTestResult,
18 TestResult,
19 TestResultDecorator,
20
21=== modified file 'testtools/testresult/__init__.py'
22--- testtools/testresult/__init__.py 2012-04-13 09:42:40 +0000
23+++ testtools/testresult/__init__.py 2012-04-13 12:37:22 +0000
24@@ -5,6 +5,7 @@
25 __all__ = [
26 'ExtendedToOriginalDecorator',
27 'MultiTestResult',
28+ 'Tagger',
29 'TestByTestResult',
30 'TestResult',
31 'TestResultDecorator',
32@@ -15,6 +16,7 @@
33 from testtools.testresult.real import (
34 ExtendedToOriginalDecorator,
35 MultiTestResult,
36+ Tagger,
37 TestByTestResult,
38 TestResult,
39 TestResultDecorator,
40
41=== modified file 'testtools/testresult/real.py'
42--- testtools/testresult/real.py 2012-04-13 09:42:40 +0000
43+++ testtools/testresult/real.py 2012-04-13 12:37:22 +0000
44@@ -6,6 +6,7 @@
45 __all__ = [
46 'ExtendedToOriginalDecorator',
47 'MultiTestResult',
48+ 'Tagger',
49 'TestResult',
50 'TestResultDecorator',
51 'ThreadsafeForwardingResult',
52@@ -726,6 +727,24 @@
53 return self.decorated.time(a_datetime)
54
55
56+class Tagger(TestResultDecorator):
57+ """Tag each test individually."""
58+
59+ def __init__(self, decorated, new_tags, gone_tags):
60+ """Wrap 'decorated' such that each test is tagged.
61+
62+ :param new_tags: Tags to be added for each test.
63+ :param gone_tags: Tags to be removed for each test.
64+ """
65+ super(Tagger, self).__init__(decorated)
66+ self._new_tags = set(new_tags)
67+ self._gone_tags = set(gone_tags)
68+
69+ def startTest(self, test):
70+ super(Tagger, self).startTest(test)
71+ self.tags(self._new_tags, self._gone_tags)
72+
73+
74 class TestByTestResult(TestResult):
75 """Call something every time a test completes."""
76
77
78=== modified file 'testtools/tests/test_testresult.py'
79--- testtools/tests/test_testresult.py 2012-04-13 09:42:40 +0000
80+++ testtools/tests/test_testresult.py 2012-04-13 12:37:22 +0000
81@@ -17,6 +17,7 @@
82 from testtools import (
83 ExtendedToOriginalDecorator,
84 MultiTestResult,
85+ Tagger,
86 TestCase,
87 TestResult,
88 TestResultDecorator,
89@@ -1815,6 +1816,30 @@
90 self.log)
91
92
93+class TestTagger(TestCase):
94+
95+ def test_tags_tests(self):
96+ result = ExtendedTestResult()
97+ tagger = Tagger(result, set(['foo']), set(['bar']))
98+ test1, test2 = self, make_test()
99+ tagger.startTest(test1)
100+ tagger.addSuccess(test1)
101+ tagger.stopTest(test1)
102+ tagger.startTest(test2)
103+ tagger.addSuccess(test2)
104+ tagger.stopTest(test2)
105+ self.assertEqual(
106+ [('startTest', test1),
107+ ('tags', set(['foo']), set(['bar'])),
108+ ('addSuccess', test1),
109+ ('stopTest', test1),
110+ ('startTest', test2),
111+ ('tags', set(['foo']), set(['bar'])),
112+ ('addSuccess', test2),
113+ ('stopTest', test2),
114+ ], result._events)
115+
116+
117 def test_suite():
118 from unittest import TestLoader
119 return TestLoader().loadTestsFromName(__name__)

Subscribers

People subscribed via source and target branches