add View.init_every_request attribute

This commit is contained in:
David Lord 2022-06-06 11:04:04 -07:00
parent aab1d9935e
commit 6e23239567
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
3 changed files with 61 additions and 13 deletions

View file

@ -240,3 +240,21 @@ def test_remove_method_from_parent(app, client):
assert client.get("/").data == b"GET"
assert client.post("/").status_code == 405
assert sorted(View.methods) == ["GET"]
def test_init_once(app, client):
n = 0
class CountInit(flask.views.View):
init_every_request = False
def __init__(self):
nonlocal n
n += 1
def dispatch_request(self):
return str(n)
app.add_url_rule("/", view_func=CountInit.as_view("index"))
assert client.get("/").data == b"1"
assert client.get("/").data == b"1"