MCPcopy Create free account
hub / github.com/pallets/flask / test_teardown_request_handler_error

Function test_teardown_request_handler_error

tests/test_basic.py:784–819  ·  view source on GitHub ↗
(app, client)

Source from the content-addressed store, hash-verified

782
783
784def test_teardown_request_handler_error(app, client):
785 called = []
786 app.testing = False
787
788 @app.teardown_request
789 def teardown_request1(exc):
790 assert type(exc) is ZeroDivisionError
791 called.append(True)
792 # This raises a new error and blows away sys.exc_info(), so we can
793 # test that all teardown_requests get passed the same original
794 # exception.
795 try:
796 raise TypeError()
797 except Exception:
798 pass
799
800 @app.teardown_request
801 def teardown_request2(exc):
802 assert type(exc) is ZeroDivisionError
803 called.append(True)
804 # This raises a new error and blows away sys.exc_info(), so we can
805 # test that all teardown_requests get passed the same original
806 # exception.
807 try:
808 raise TypeError()
809 except Exception:
810 pass
811
812 @app.route("/")
813 def fails():
814 raise ZeroDivisionError
815
816 rv = client.get("/")
817 assert rv.status_code == 500
818 assert b"Internal Server Error" in rv.data
819 assert len(called) == 2
820
821
822def test_before_after_request_order(app, client):

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected