MCPcopy
hub / github.com/pallets/flask / test_blueprint_specific_user_error_handling

Function test_blueprint_specific_user_error_handling

tests/test_blueprints.py:46–77  ·  view source on GitHub ↗
(app, client)

Source from the content-addressed store, hash-verified

44
45
46def test_blueprint_specific_user_error_handling(app, client):
47 class MyDecoratorException(Exception):
48 pass
49
50 class MyFunctionException(Exception):
51 pass
52
53 blue = flask.Blueprint("blue", __name__)
54
55 @blue.errorhandler(MyDecoratorException)
56 def my_decorator_exception_handler(e):
57 assert isinstance(e, MyDecoratorException)
58 return "boom"
59
60 def my_function_exception_handler(e):
61 assert isinstance(e, MyFunctionException)
62 return "bam"
63
64 blue.register_error_handler(MyFunctionException, my_function_exception_handler)
65
66 @blue.route("/decorator")
67 def blue_deco_test():
68 raise MyDecoratorException()
69
70 @blue.route("/function")
71 def blue_func_test():
72 raise MyFunctionException()
73
74 app.register_blueprint(blue)
75
76 assert client.get("/decorator").data == b"boom"
77 assert client.get("/function").data == b"bam"
78
79
80def test_blueprint_app_error_handling(app, client):

Callers

nothing calls this directly

Calls 3

register_blueprintMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…