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

Function test_error_handling

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

Source from the content-addressed store, hash-verified

858
859
860def test_error_handling(app, client):
861 app.testing = False
862
863 @app.errorhandler(404)
864 def not_found(e):
865 return "not found", 404
866
867 @app.errorhandler(500)
868 def internal_server_error(e):
869 return "internal server error", 500
870
871 @app.errorhandler(Forbidden)
872 def forbidden(e):
873 return "forbidden", 403
874
875 @app.route("/")
876 def index():
877 flask.abort(404)
878
879 @app.route("/error")
880 def error():
881 raise ZeroDivisionError
882
883 @app.route("/forbidden")
884 def error2():
885 flask.abort(403)
886
887 rv = client.get("/")
888 assert rv.status_code == 404
889 assert rv.data == b"not found"
890 rv = client.get("/error")
891 assert rv.status_code == 500
892 assert b"internal server error" == rv.data
893 rv = client.get("/forbidden")
894 assert rv.status_code == 403
895 assert b"forbidden" == rv.data
896
897
898def test_error_handling_processing(app, client):

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected