flask-testing
flask-testing copied to clipboard
Not perfect exception handling in TestCase.__call__
In the TestCase class, there's this method:
def __call__(self, result=None):
"""
Does the required setup, doing it here
means you don't have to call super.setUp
in subclasses.
"""
try:
self._pre_setup()
super(TestCase, self).__call__(result)
finally:
self._post_teardown()
The problem is that if create_app() throws an exception when called in _pre_setup(), then the self._orig_response_class field is never set/created. And because of the exception, the 'finally' block is executed, and on line 101, _post_teardown() is trying to reference that field, and that throws another exception (saying that the field doesn't exist). So:
- The original exception is never reported.
- The user sees a completely random exception instead.