Merge lp:~lifeless/testtools/startTestRun into lp:~testtools-committers/testtools/trunk

Proposed by Robert Collins
Status: Merged
Merged at revision: not available
Proposed branch: lp:~lifeless/testtools/startTestRun
Merge into: lp:~testtools-committers/testtools/trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~lifeless/testtools/startTestRun
Reviewer Review Type Date Requested Status
Jonathan Lange Approve
Review via email: mp+10773@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

Add startTestRun/stopTestRun

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

Make it so.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'testtools/testresult.py'
2--- testtools/testresult.py 2009-04-11 23:23:01 +0000
3+++ testtools/testresult.py 2009-08-26 22:02:12 +0000
4@@ -39,8 +39,23 @@
5 skip_list = self.skip_reasons.setdefault(reason, [])
6 skip_list.append(test)
7
8+ def startTestRun(self):
9+ """Called before a test run starts.
10+
11+ New in python 2.7
12+ """
13+
14+ def stopTestRun(self):
15+ """Called after a test run completes
16+
17+ New in python 2.7
18+ """
19+
20 def done(self):
21- """Called when the test runner is done."""
22+ """Called when the test runner is done.
23+
24+ deprecated in favour of stopTestRun.
25+ """
26
27
28 class MultiTestResult(TestResult):
29@@ -72,6 +87,12 @@
30 def addSuccess(self, test):
31 self._dispatch('addSuccess', test)
32
33+ def startTestRun(self):
34+ self._dispatch('startTestRun')
35+
36+ def stopTestRun(self):
37+ self._dispatch('stopTestRun')
38+
39 def done(self):
40 self._dispatch('done')
41
42@@ -140,6 +161,20 @@
43 finally:
44 self.semaphore.release()
45
46+ def startTestRun(self):
47+ self.semaphore.acquire()
48+ try:
49+ self.result.startTestRun()
50+ finally:
51+ self.semaphore.release()
52+
53+ def stopTestRun(self):
54+ self.semaphore.acquire()
55+ try:
56+ self.result.stopTestRun()
57+ finally:
58+ self.semaphore.release()
59+
60 def done(self):
61 self.semaphore.acquire()
62 try:
63
64=== modified file 'testtools/tests/helpers.py'
65--- testtools/tests/helpers.py 2009-02-28 04:22:53 +0000
66+++ testtools/tests/helpers.py 2009-08-26 22:02:12 +0000
67@@ -41,6 +41,14 @@
68 self._events.append(('addSuccess', test))
69 super(LoggingResult, self).addSuccess(test)
70
71+ def startTestRun(self):
72+ self._events.append('startTestRun')
73+ super(LoggingResult, self).startTestRun()
74+
75+ def stopTestRun(self):
76+ self._events.append('stopTestRun')
77+ super(LoggingResult, self).stopTestRun()
78+
79 def done(self):
80 self._events.append('done')
81 super(LoggingResult, self).done()
82
83=== modified file 'testtools/tests/test_testresult.py'
84--- testtools/tests/test_testresult.py 2009-03-18 12:30:47 +0000
85+++ testtools/tests/test_testresult.py 2009-08-26 22:02:12 +0000
86@@ -24,6 +24,12 @@
87 result = self.makeResult()
88 result.addSkip(self, u"Skipped for some reason")
89
90+ def test_startStopTestRun(self):
91+ # Calling startTestRun completes ok.
92+ result = self.makeResult()
93+ result.startTestRun()
94+ result.stopTestRun()
95+
96
97 class TestTestResultContract(TestTestResultContract):
98
99@@ -144,6 +150,18 @@
100 self.multiResult.addError(self, exc_info)
101 self.assertResultLogsEqual([('addError', self, exc_info)])
102
103+ def test_startTestRun(self):
104+ # Calling `startTestRun` on a `MultiTestResult` forwards to all its
105+ # `TestResult`s.
106+ self.multiResult.startTestRun()
107+ self.assertResultLogsEqual([('startTestRun')])
108+
109+ def test_stopTestRun(self):
110+ # Calling `stopTestRun` on a `MultiTestResult` forwards to all its
111+ # `TestResult`s.
112+ self.multiResult.stopTestRun()
113+ self.assertResultLogsEqual([('stopTestRun')])
114+
115
116 class TestThreadSafeForwardingResult(TestWithFakeExceptions):
117 """Tests for `MultiTestResult`."""
118@@ -161,6 +179,20 @@
119 self.result1.stopTest(self)
120 self.assertEqual([], self.target._events)
121
122+ def test_startTestRun(self):
123+ self.result1.startTestRun()
124+ self.result2 = ThreadsafeForwardingResult(self.target,
125+ self.result_semaphore)
126+ self.result2.startTestRun()
127+ self.assertEqual(["startTestRun", "startTestRun"], self.target._events)
128+
129+ def test_stopTestRun(self):
130+ self.result1.stopTestRun()
131+ self.result2 = ThreadsafeForwardingResult(self.target,
132+ self.result_semaphore)
133+ self.result2.stopTestRun()
134+ self.assertEqual(["stopTestRun", "stopTestRun"], self.target._events)
135+
136 def test_done(self):
137 self.result1.done()
138 self.result2 = ThreadsafeForwardingResult(self.target,
139@@ -169,7 +201,7 @@
140 self.assertEqual(["done", "done"], self.target._events)
141
142 def test_forwarding_methods(self):
143- # error, failure, skip and success are forwarded.
144+ # error, failure, skip and success are forwarded in batches.
145 exc_info1 = self.makeExceptionInfo(RuntimeError, 'error')
146 self.result1.addError(self, exc_info1)
147 exc_info2 = self.makeExceptionInfo(AssertionError, 'failure')

Subscribers

People subscribed via source and target branches