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

Function test_error_handler_subclass

tests/test_user_error_handler.py:61–97  ·  view source on GitHub ↗
(app)

Source from the content-addressed store, hash-verified

59
60
61def test_error_handler_subclass(app):
62 class ParentException(Exception):
63 pass
64
65 class ChildExceptionUnregistered(ParentException):
66 pass
67
68 class ChildExceptionRegistered(ParentException):
69 pass
70
71 @app.errorhandler(ParentException)
72 def parent_exception_handler(e):
73 assert isinstance(e, ParentException)
74 return "parent"
75
76 @app.errorhandler(ChildExceptionRegistered)
77 def child_exception_handler(e):
78 assert isinstance(e, ChildExceptionRegistered)
79 return "child-registered"
80
81 @app.route("/parent")
82 def parent_test():
83 raise ParentException()
84
85 @app.route("/child-unregistered")
86 def unregistered_test():
87 raise ChildExceptionUnregistered()
88
89 @app.route("/child-registered")
90 def registered_test():
91 raise ChildExceptionRegistered()
92
93 c = app.test_client()
94
95 assert c.get("/parent").data == b"parent"
96 assert c.get("/child-unregistered").data == b"parent"
97 assert c.get("/child-registered").data == b"child-registered"
98
99
100def test_error_handler_http_subclass(app):

Callers

nothing calls this directly

Calls 2

test_clientMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected