← Back to team overview

testtools-dev team mailing list archive

[Merge] lp:~tcole/testtools/use-super into lp:testtools

 

Tim Cole has proposed merging lp:~tcole/testtools/use-super into lp:testtools.

Requested reviews:
  testtools developers (testtools-dev)
Related bugs:
  Bug #771508 in testtools: "testtools should use super() when calling setUp/tearDown"
  https://bugs.launchpad.net/testtools/+bug/771508

For more details, see:
https://code.launchpad.net/~tcole/testtools/use-super/+merge/60850

Use super() from setUp() and tearDown(); unittest.TestCase has been a new-style class since python 2.4.
-- 
https://code.launchpad.net/~tcole/testtools/use-super/+merge/60850
Your team testtools developers is requested to review the proposed merge of lp:~tcole/testtools/use-super into lp:testtools.
=== modified file 'testtools/testcase.py'
--- testtools/testcase.py	2011-04-20 23:45:52 +0000
+++ testtools/testcase.py	2011-05-12 23:04:15 +0000
@@ -124,7 +124,7 @@
             ``TestCase.run_tests_with`` if given.
         """
         runTest = kwargs.pop('runTest', None)
-        unittest.TestCase.__init__(self, *args, **kwargs)
+        super(TestCase, self).__init__(*args, **kwargs)
         self._cleanups = []
         self._unique_id_gen = itertools.count(1)
         # Generators to ensure unique traceback ids.  Maps traceback label to
@@ -535,10 +535,11 @@
                 content.Content(content_object.content_type, content_callback))
 
     def setUp(self):
-        unittest.TestCase.setUp(self)
+        super(TestCase, self).setUp()
         self.__setup_called = True
 
     def tearDown(self):
+        super(TestCase, self).tearDown()
         unittest.TestCase.tearDown(self)
         self.__teardown_called = True
 

=== modified file 'testtools/tests/test_testtools.py'
--- testtools/tests/test_testtools.py	2011-04-20 23:45:52 +0000
+++ testtools/tests/test_testtools.py	2011-05-12 23:04:15 +0000
@@ -1138,6 +1138,36 @@
         self.assertIs(marker, value)
 
 
+class TestTestCaseSuper(TestCase):
+    def test_setup_uses_super(self):
+        class OtherBaseCase(unittest.TestCase):
+            setup_called = False
+            def setUp(self):
+                self.setup_called = True
+                super(OtherBaseCase, self).setUp()
+        class OurCase(TestCase, OtherBaseCase):
+            def runTest(self):
+                pass
+        test = OurCase()
+        test.setUp()
+        test.tearDown()
+        self.assertTrue(test.setup_called)
+
+    def test_teardown_uses_super(self):
+        class OtherBaseCase(unittest.TestCase):
+            teardown_called = False
+            def tearDown(self):
+                self.teardown_called = True
+                super(OtherBaseCase, self).tearDown()
+        class OurCase(TestCase, OtherBaseCase):
+            def runTest(self):
+                pass
+        test = OurCase()
+        test.setUp()
+        test.tearDown()
+        self.assertTrue(test.teardown_called)
+
+
 def test_suite():
     from unittest import TestLoader
     return TestLoader().loadTestsFromName(__name__)


Follow ups