Skip to content

Commit d76ca43

Browse files
committed
Merge pull request pallets#1196 from davide-ceretti/add-tearing-down-signal-unittest
Add unittest for appcontext_tearing_down signal
2 parents b923712 + 93c190a commit d76ca43

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/test_signals.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,24 @@ def record(sender, message, category):
156156
assert category == 'notice'
157157
finally:
158158
flask.message_flashed.disconnect(record, app)
159+
160+
def test_appcontext_tearing_down_signal():
161+
app = flask.Flask(__name__)
162+
recorded = []
163+
164+
def record_teardown(sender, **kwargs):
165+
recorded.append(('tear_down', kwargs))
166+
167+
@app.route('/')
168+
def index():
169+
1 // 0
170+
171+
flask.appcontext_tearing_down.connect(record_teardown, app)
172+
try:
173+
with app.test_client() as c:
174+
rv = c.get('/')
175+
assert rv.status_code == 500
176+
assert recorded == []
177+
assert recorded == [('tear_down', {'exc': None})]
178+
finally:
179+
flask.appcontext_tearing_down.disconnect(record_teardown, app)

0 commit comments

Comments
 (0)