refactor stream_with_context for async views

This commit is contained in:
David Lord 2025-08-19 08:18:55 -07:00
parent 49b7e7bc8f
commit 9822a03515
No known key found for this signature in database
GPG key ID: 43368A7AA8CC5926
3 changed files with 62 additions and 31 deletions

View file

@ -306,6 +306,29 @@ class TestStreaming:
rv = client.get("/")
assert rv.data == b"flask"
def test_async_view(self, app, client):
@app.route("/")
async def index():
flask.session["test"] = "flask"
@flask.stream_with_context
def gen():
yield flask.session["test"]
return flask.Response(gen())
# response is closed without reading stream
client.get().close()
# response stream is read
assert client.get().text == "flask"
# same as above, but with client context preservation
with client:
client.get().close()
with client:
assert client.get().text == "flask"
class TestHelpers:
@pytest.mark.parametrize(