librelist archives

« back to archive

app.handle_exception and app.test_request_context

app.handle_exception and app.test_request_context

From:
Christian Jauvin
Date:
2013-03-29 @ 02:18
Hi,

I noticed that app.handle_exception doesn't seem to be called when the
exception occurs with an app.test_request_context:

from flask import *

app = Flask('foo')
app.handle_exception = lambda e: 'exception!'

@app.route('/foo')
def foo():
    x = 1 / 0
    return 'ok'

if __name__ == '__main__':
    #app.run(port=81) # handle_exception works here
    with app.test_request_context('/foo'):
        print app.dispatch_request() # but here it doesn't work..

Is this the expected behavior?

Thanks,

Christian