The example code below is similar to this answer, it runs a function after a Flask
response has been returned. This works just fine.
My question is how can I unit test via the Flask.test_client
that my_task()
was called during the test ?
It seems that the Flask.test_client
by default does not trigger after_this_request
actions.
@app.route('/')
def index():
# create response
msg = 'Hello World!'
@flask.after_this_request
def add_close_action(response):
@response.call_on_close
def process_after_request():
# post-response tasks
self.my_task()
return response
return msg