clean up
This commit is contained in:
parent
a417e41d27
commit
9560f22bb6
2 changed files with 8 additions and 16 deletions
|
|
@ -1485,8 +1485,8 @@ class Flask(_PackageBoundObject):
|
||||||
context it would also be called when you pop a request context.
|
context it would also be called when you pop a request context.
|
||||||
|
|
||||||
When a teardown function was called because of an unhandled exception
|
When a teardown function was called because of an unhandled exception
|
||||||
it will be passed an error object. Note that if a :meth:`errorhandler`
|
it will be passed an error object. If an :meth:`errorhandler` is
|
||||||
is registered, it will handle the exception and the teardown will not
|
registered, it will handle the exception and the teardown will not
|
||||||
receive it.
|
receive it.
|
||||||
|
|
||||||
The return values of teardown functions are ignored.
|
The return values of teardown functions are ignored.
|
||||||
|
|
|
||||||
|
|
@ -97,13 +97,10 @@ def test_app_tearing_down_with_handled_exception_by_except_block(app):
|
||||||
assert cleanup_stuff == [None]
|
assert cleanup_stuff == [None]
|
||||||
|
|
||||||
|
|
||||||
def test_app_tearing_down_with_handled_exception_by_app_handler(app):
|
def test_app_tearing_down_with_handled_exception_by_app_handler(app, client):
|
||||||
|
app.config['PROPAGATE_EXCEPTIONS'] = True
|
||||||
cleanup_stuff = []
|
cleanup_stuff = []
|
||||||
|
|
||||||
class AppConfig():
|
|
||||||
PROPAGATE_EXCEPTIONS = True
|
|
||||||
app.config.from_object(AppConfig())
|
|
||||||
|
|
||||||
@app.teardown_appcontext
|
@app.teardown_appcontext
|
||||||
def cleanup(exception):
|
def cleanup(exception):
|
||||||
cleanup_stuff.append(exception)
|
cleanup_stuff.append(exception)
|
||||||
|
|
@ -116,20 +113,16 @@ def test_app_tearing_down_with_handled_exception_by_app_handler(app):
|
||||||
def handler(f):
|
def handler(f):
|
||||||
return flask.jsonify(str(f))
|
return flask.jsonify(str(f))
|
||||||
|
|
||||||
test_client = app.test_client()
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
test_client.get('/')
|
client.get('/')
|
||||||
|
|
||||||
assert cleanup_stuff == [None]
|
assert cleanup_stuff == [None]
|
||||||
|
|
||||||
|
|
||||||
def test_app_tearing_down_with_unhandled_exception(app):
|
def test_app_tearing_down_with_unhandled_exception(app, client):
|
||||||
|
app.config['PROPAGATE_EXCEPTIONS'] = True
|
||||||
cleanup_stuff = []
|
cleanup_stuff = []
|
||||||
|
|
||||||
class AppConfig():
|
|
||||||
PROPAGATE_EXCEPTIONS = True
|
|
||||||
app.config.from_object(AppConfig())
|
|
||||||
|
|
||||||
@app.teardown_appcontext
|
@app.teardown_appcontext
|
||||||
def cleanup(exception):
|
def cleanup(exception):
|
||||||
cleanup_stuff.append(exception)
|
cleanup_stuff.append(exception)
|
||||||
|
|
@ -138,10 +131,9 @@ def test_app_tearing_down_with_unhandled_exception(app):
|
||||||
def index():
|
def index():
|
||||||
raise Exception('dummy')
|
raise Exception('dummy')
|
||||||
|
|
||||||
test_client = app.test_client()
|
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
test_client.get('/')
|
client.get('/')
|
||||||
|
|
||||||
assert len(cleanup_stuff) == 1
|
assert len(cleanup_stuff) == 1
|
||||||
assert isinstance(cleanup_stuff[0], Exception)
|
assert isinstance(cleanup_stuff[0], Exception)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue