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

Function test_init_once

tests/test_views.py:245–260  ·  view source on GitHub ↗
(app, client)

Source from the content-addressed store, hash-verified

243
244
245def test_init_once(app, client):
246 n = 0
247
248 class CountInit(flask.views.View):
249 init_every_request = False
250
251 def __init__(self):
252 nonlocal n
253 n += 1
254
255 def dispatch_request(self):
256 return str(n)
257
258 app.add_url_rule("/", view_func=CountInit.as_view("index"))
259 assert client.get("/").data == b"1"
260 assert client.get("/").data == b"1"

Callers

nothing calls this directly

Calls 3

as_viewMethod · 0.80
add_url_ruleMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected