|
|
@ -81,7 +81,7 @@ def test_app_tearing_down_with_previous_exception(app): |
|
|
|
assert cleanup_stuff == [None] |
|
|
|
assert cleanup_stuff == [None] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_app_tearing_down_with_handled_exception(app): |
|
|
|
def test_app_tearing_down_with_handled_exception_by_except_block(app): |
|
|
|
cleanup_stuff = [] |
|
|
|
cleanup_stuff = [] |
|
|
|
|
|
|
|
|
|
|
|
@app.teardown_appcontext |
|
|
|
@app.teardown_appcontext |
|
|
@ -97,6 +97,57 @@ def test_app_tearing_down_with_handled_exception(app): |
|
|
|
assert cleanup_stuff == [None] |
|
|
|
assert cleanup_stuff == [None] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_app_tearing_down_with_handled_exception_by_app_handler(app): |
|
|
|
|
|
|
|
cleanup_stuff = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AppConfig(): |
|
|
|
|
|
|
|
PROPAGATE_EXCEPTIONS = True |
|
|
|
|
|
|
|
app.config.from_object(AppConfig()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.teardown_appcontext |
|
|
|
|
|
|
|
def cleanup(exception): |
|
|
|
|
|
|
|
cleanup_stuff.append(exception) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/') |
|
|
|
|
|
|
|
def index(): |
|
|
|
|
|
|
|
raise Exception('dummy') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(Exception) |
|
|
|
|
|
|
|
def handler(f): |
|
|
|
|
|
|
|
return flask.jsonify(str(f)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_client = app.test_client() |
|
|
|
|
|
|
|
with app.app_context(): |
|
|
|
|
|
|
|
test_client.get('/') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert cleanup_stuff == [None] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_app_tearing_down_with_unhandled_exception(app): |
|
|
|
|
|
|
|
cleanup_stuff = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AppConfig(): |
|
|
|
|
|
|
|
PROPAGATE_EXCEPTIONS = True |
|
|
|
|
|
|
|
app.config.from_object(AppConfig()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.teardown_appcontext |
|
|
|
|
|
|
|
def cleanup(exception): |
|
|
|
|
|
|
|
cleanup_stuff.append(exception) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/') |
|
|
|
|
|
|
|
def index(): |
|
|
|
|
|
|
|
raise Exception('dummy') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_client = app.test_client() |
|
|
|
|
|
|
|
with pytest.raises(Exception): |
|
|
|
|
|
|
|
with app.app_context(): |
|
|
|
|
|
|
|
test_client.get('/') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert len(cleanup_stuff) == 1 |
|
|
|
|
|
|
|
assert isinstance(cleanup_stuff[0], Exception) |
|
|
|
|
|
|
|
assert str(cleanup_stuff[0]) == 'dummy' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_app_ctx_globals_methods(app, app_ctx): |
|
|
|
def test_app_ctx_globals_methods(app, app_ctx): |
|
|
|
# get |
|
|
|
# get |
|
|
|
assert flask.g.get('foo') is None |
|
|
|
assert flask.g.get('foo') is None |
|
|
|