From 93c190a8fd81355dd4ac4f567821ff28ad021d5b Mon Sep 17 00:00:00 2001 From: Davide Ceretti Date: Fri, 3 Oct 2014 21:04:33 +0100 Subject: [PATCH] Add unittest for appcontext_tearing_down signal --- tests/test_signals.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_signals.py b/tests/test_signals.py index 79283584..b726d7b4 100644 --- a/tests/test_signals.py +++ b/tests/test_signals.py @@ -156,3 +156,24 @@ def test_flash_signal(): assert category == 'notice' finally: flask.message_flashed.disconnect(record, app) + +def test_appcontext_tearing_down_signal(): + app = flask.Flask(__name__) + recorded = [] + + def record_teardown(sender, **kwargs): + recorded.append(('tear_down', kwargs)) + + @app.route('/') + def index(): + 1 // 0 + + flask.appcontext_tearing_down.connect(record_teardown, app) + try: + with app.test_client() as c: + rv = c.get('/') + assert rv.status_code == 500 + assert recorded == [] + assert recorded == [('tear_down', {'exc': None})] + finally: + flask.appcontext_tearing_down.disconnect(record_teardown, app)