Skip to content

Commit

Permalink
Make AsyncTestCase call tearDown in super class.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bwbeach committed Mar 14, 2011
1 parent 6923539 commit 6f0a8a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tornado/test/testing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,33 @@ def test_exception_in_callback(self):
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()
1 change: 1 addition & 0 deletions tornado/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def tearDown(self):
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
Expand Down

0 comments on commit 6f0a8a7

Please sign in to comment.