From: Ben Darnell Date: Sat, 23 Feb 2013 15:53:31 +0000 (-0500) Subject: Move fallback exception raising in AsyncTestCase from run() to tearDown(). X-Git-Tag: v3.0.0~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4731072f6171180c6fa07fc691646cb0cf33ed23;p=thirdparty%2Ftornado.git Move fallback exception raising in AsyncTestCase from run() to tearDown(). This allows the exception to be reported as a test failure instead of making the test run blow up. --- diff --git a/tornado/testing.py b/tornado/testing.py index 30fe4e29c..8e635831c 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -165,6 +165,11 @@ class AsyncTestCase(unittest.TestCase): # set FD_CLOEXEC on its file descriptors) self.io_loop.close(all_fds=True) super(AsyncTestCase, self).tearDown() + # In case an exception escaped or the StackContext caught an exception + # when there wasn't a wait() to re-raise it, do so here. + # This is our last chance to raise an exception in a way that the + # unittest machinery understands. + self.__rethrow() def get_new_ioloop(self): """Creates a new IOLoop for this test. May be overridden in @@ -187,8 +192,10 @@ class AsyncTestCase(unittest.TestCase): def run(self, result=None): with ExceptionStackContext(self._handle_exception): super(AsyncTestCase, self).run(result) - # In case an exception escaped super.run or the StackContext caught - # an exception when there wasn't a wait() to re-raise it, do so here. + # As a last resort, if an exception escaped super.run() and wasn't + # re-raised in tearDown, raise it here. This will cause the + # unittest run to fail messily, but that's better than silently + # ignoring an error. self.__rethrow() def stop(self, _arg=None, **kwargs):