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

Function test_async_before_after_request

tests/test_async.py:97–145  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

95
96
97def test_async_before_after_request():
98 app_before_called = False
99 app_after_called = False
100 bp_before_called = False
101 bp_after_called = False
102
103 app = Flask(__name__)
104
105 @app.route("/")
106 def index():
107 return ""
108
109 @app.before_request
110 async def before():
111 nonlocal app_before_called
112 app_before_called = True
113
114 @app.after_request
115 async def after(response):
116 nonlocal app_after_called
117 app_after_called = True
118 return response
119
120 blueprint = Blueprint("bp", __name__)
121
122 @blueprint.route("/")
123 def bp_index():
124 return ""
125
126 @blueprint.before_request
127 async def bp_before():
128 nonlocal bp_before_called
129 bp_before_called = True
130
131 @blueprint.after_request
132 async def bp_after(response):
133 nonlocal bp_after_called
134 bp_after_called = True
135 return response
136
137 app.register_blueprint(blueprint, url_prefix="/bp")
138
139 test_client = app.test_client()
140 test_client.get("/")
141 assert app_before_called
142 assert app_after_called
143 test_client.get("/bp/")
144 assert bp_before_called
145 assert bp_after_called

Callers

nothing calls this directly

Calls 5

test_clientMethod · 0.95
FlaskClass · 0.90
BlueprintClass · 0.90
register_blueprintMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected