flask-testing icon indicating copy to clipboard operation
flask-testing copied to clipboard

Not perfect exception handling in TestCase.__call__

Open jarus opened this issue 12 years ago • 0 comments

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:

  1. The original exception is never reported.
  2. The user sees a completely random exception instead.

jarus avatar Mar 07 '13 19:03 jarus