]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Make AsyncTestCase call tearDown in super class. 232/head
authorBrian Beach <coder@beachfamily.net>
Mon, 14 Mar 2011 15:34:19 +0000 (11:34 -0400)
committerBrian Beach <coder@beachfamily.net>
Mon, 14 Mar 2011 15:34:19 +0000 (11:34 -0400)
The setUp method was calling super, but tearDown wasn't.  Now they
both are.

This change includes a new unit test case to verify the fix.

tornado/test/testing_test.py
tornado/testing.py

index 4391675d63da74b40a2e20c1dddeaa019356767c..bdca031ed37bc998ef1090d327196359d9ab5359 100644 (file)
@@ -11,5 +11,33 @@ class AsyncTestCaseTest(AsyncTestCase, LogTrapTestCase):
         except ZeroDivisionError:
             pass
 
+class SetUpTearDownTest(unittest.TestCase):
+    def test_set_up_tear_down(self):
+        """
+        This test makes sure that AsyncTestCase calls super methods for
+        setUp and tearDown.
+
+        InheritBoth is a subclass of both AsyncTestCase and
+        SetUpTearDown, with the ordering so that the super of
+        AsyncTestCase will be SetUpTearDown.
+        """
+        events = []
+        result = unittest.TestResult()
+
+        class SetUpTearDown(unittest.TestCase):
+            def setUp(self):
+                events.append('setUp')
+
+            def tearDown(self):
+                events.append('tearDown')
+
+        class InheritBoth(AsyncTestCase, SetUpTearDown):
+            def test(self):
+                events.append('test')
+
+        InheritBoth('test').run(result)
+        expected = ['setUp', 'test', 'tearDown']
+        self.assertEqual(expected, events)
+
 if __name__ == '__main__':
-    unittest.main
+    unittest.main()
index 507a378e05341a0a37add2bc789b7be2b0028565..a92f337f4069ecb84c99500489a5e300ebb464da 100644 (file)
@@ -112,6 +112,7 @@ class AsyncTestCase(unittest.TestCase):
                     logging.debug("error closing fd %d", fd, exc_info=True)
             self.io_loop._waker_reader.close()
             self.io_loop._waker_writer.close()
+        super(AsyncTestCase, self).tearDown()
 
     def get_new_ioloop(self):
         '''Creates a new IOLoop for this test.  May be overridden in