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

Proposed by Robert Collins
Status: Merged
Merged at revision: not available
Proposed branch: lp:~lifeless/testtools/344023
Merge into: lp:~testtools-committers/testtools/trunk
Diff against target: 134 lines
3 files modified
testtools/testcase.py (+14/-0)
testtools/tests/test_testresult.py (+2/-0)
testtools/tests/test_testtools.py (+28/-0)
To merge this branch: bzr merge lp:~lifeless/testtools/344023
Reviewer Review Type Date Requested Status
Jonathan Lange Approve
Review via email: mp+13947@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

Cause failing to upcall to setup or teardown to cause a test to error.

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

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'testtools/testcase.py'
--- testtools/testcase.py 2009-10-25 10:19:09 +0000
+++ testtools/testcase.py 2009-10-26 11:30:33 +0000
@@ -29,6 +29,8 @@
29 unittest.TestCase.__init__(self, *args, **kwargs)29 unittest.TestCase.__init__(self, *args, **kwargs)
30 self._cleanups = []30 self._cleanups = []
31 self._last_unique_id = 031 self._last_unique_id = 0
32 self.__setup_called = False
33 self.__teardown_callled = False
3234
33 def __eq__(self, other):35 def __eq__(self, other):
34 eq = getattr(unittest.TestCase, '__eq__', None)36 eq = getattr(unittest.TestCase, '__eq__', None)
@@ -165,6 +167,8 @@
165 try:167 try:
166 try:168 try:
167 self.setUp()169 self.setUp()
170 if not self.__setup_called:
171 raise ValueError("setup was not called")
168 except KeyboardInterrupt:172 except KeyboardInterrupt:
169 raise173 raise
170 except self.skipException, e:174 except self.skipException, e:
@@ -192,6 +196,8 @@
192 cleanupsOk = self._runCleanups(result)196 cleanupsOk = self._runCleanups(result)
193 try:197 try:
194 self.tearDown()198 self.tearDown()
199 if not self.__teardown_callled:
200 raise ValueError("teardown was not called")
195 except KeyboardInterrupt:201 except KeyboardInterrupt:
196 raise202 raise
197 except:203 except:
@@ -202,6 +208,14 @@
202 finally:208 finally:
203 result.stopTest(self)209 result.stopTest(self)
204210
211 def setUp(self):
212 unittest.TestCase.setUp(self)
213 self.__setup_called = True
214
215 def tearDown(self):
216 unittest.TestCase.tearDown(self)
217 self.__teardown_callled = True
218
205219
206def clone_test_with_new_id(test, new_id):220def clone_test_with_new_id(test, new_id):
207 """Copy a TestCase, and give the copied test a new id."""221 """Copy a TestCase, and give the copied test a new id."""
208222
=== modified file 'testtools/tests/test_testresult.py'
--- testtools/tests/test_testresult.py 2009-08-26 22:02:12 +0000
+++ testtools/tests/test_testresult.py 2009-10-26 11:30:33 +0000
@@ -91,6 +91,7 @@
91 """Tests for `MultiTestResult`."""91 """Tests for `MultiTestResult`."""
9292
93 def setUp(self):93 def setUp(self):
94 TestWithFakeExceptions.setUp(self)
94 self.result1 = LoggingResult([])95 self.result1 = LoggingResult([])
95 self.result2 = LoggingResult([])96 self.result2 = LoggingResult([])
96 self.multiResult = MultiTestResult(self.result1, self.result2)97 self.multiResult = MultiTestResult(self.result1, self.result2)
@@ -167,6 +168,7 @@
167 """Tests for `MultiTestResult`."""168 """Tests for `MultiTestResult`."""
168169
169 def setUp(self):170 def setUp(self):
171 TestWithFakeExceptions.setUp(self)
170 self.result_semaphore = threading.Semaphore(1)172 self.result_semaphore = threading.Semaphore(1)
171 self.target = LoggingResult([])173 self.target = LoggingResult([])
172 self.result1 = ThreadsafeForwardingResult(self.target,174 self.result1 = ThreadsafeForwardingResult(self.target,
173175
=== modified file 'testtools/tests/test_testtools.py'
--- testtools/tests/test_testtools.py 2009-10-25 10:19:09 +0000
+++ testtools/tests/test_testtools.py 2009-10-26 11:30:33 +0000
@@ -231,6 +231,7 @@
231 """A test that logs calls to setUp, runTest and tearDown."""231 """A test that logs calls to setUp, runTest and tearDown."""
232232
233 def setUp(self):233 def setUp(self):
234 TestCase.setUp(self)
234 self._calls = ['setUp']235 self._calls = ['setUp']
235236
236 def brokenSetUp(self):237 def brokenSetUp(self):
@@ -243,8 +244,10 @@
243244
244 def tearDown(self):245 def tearDown(self):
245 self._calls.append('tearDown')246 self._calls.append('tearDown')
247 TestCase.tearDown(self)
246248
247 def setUp(self):249 def setUp(self):
250 TestCase.setUp(self)
248 self._result_calls = []251 self._result_calls = []
249 self.test = TestAddCleanup.LoggingTest('runTest')252 self.test = TestAddCleanup.LoggingTest('runTest')
250 self.logging_result = LoggingResult(self._result_calls)253 self.logging_result = LoggingResult(self._result_calls)
@@ -382,6 +385,29 @@
382 "the original test instance should be unchanged.")385 "the original test instance should be unchanged.")
383386
384387
388class TestSetupTearDown(TestCase):
389
390 def test_setUpNotCalled(self):
391 class DoesnotcallsetUp(TestCase):
392 def setUp(self):
393 pass
394 def test_method(self):
395 pass
396 result = unittest.TestResult()
397 DoesnotcallsetUp('test_method').run(result)
398 self.assertEqual(1, len(result.errors))
399
400 def test_tearDownNotCalled(self):
401 class DoesnotcalltearDown(TestCase):
402 def test_method(self):
403 pass
404 def tearDown(self):
405 pass
406 result = unittest.TestResult()
407 DoesnotcalltearDown('test_method').run(result)
408 self.assertEqual(1, len(result.errors))
409
410
385class TestSkipping(TestCase):411class TestSkipping(TestCase):
386 """Tests for skipping of tests functionality."""412 """Tests for skipping of tests functionality."""
387413
@@ -391,6 +417,7 @@
391 def test_skipException_in_setup_calls_result_addSkip(self):417 def test_skipException_in_setup_calls_result_addSkip(self):
392 class TestThatRaisesInSetUp(TestCase):418 class TestThatRaisesInSetUp(TestCase):
393 def setUp(self):419 def setUp(self):
420 TestCase.setUp(self)
394 self.skip("skipping this test")421 self.skip("skipping this test")
395 def test_that_passes(self):422 def test_that_passes(self):
396 pass423 pass
@@ -417,6 +444,7 @@
417 def test_skip__in_setup_with_old_result_object_calls_addError(self):444 def test_skip__in_setup_with_old_result_object_calls_addError(self):
418 class SkippingTest(TestCase):445 class SkippingTest(TestCase):
419 def setUp(self):446 def setUp(self):
447 TestCase.setUp(self)
420 raise self.skipException("skipping this test")448 raise self.skipException("skipping this test")
421 def test_that_raises_skipException(self):449 def test_that_raises_skipException(self):
422 pass450 pass

Subscribers

People subscribed via source and target branches