Skip to content

Commit

Permalink
More explicit explanation: session testing
Browse files Browse the repository at this point in the history
Use a more explicit explanation on how to write code to test own code
when sessions are needed.
The previous code was not fully explicit that the client is supposed
to be called after the session transaction and not during.
  • Loading branch information
brunoais authored and davidism committed May 17, 2019
1 parent 55801b5 commit 6142aa6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,15 @@ This however does not make it possible to also modify the session or to
access the session before a request was fired. Starting with Flask 0.8 we
provide a so called “session transaction” which simulates the appropriate
calls to open a session in the context of the test client and to modify
it. At the end of the transaction the session is stored. This works
independently of the session backend used::
it. At the end of the transaction the session is stored and ready to be
used by the test client. This works independently of the session backend used::

with app.test_client() as c:
with c.session_transaction() as sess:
sess['a_key'] = 'a value'

# once this is reached the session was stored
# once this is reached the session was stored and ready to be used by the client
c.get(...)

Note that in this case you have to use the ``sess`` object instead of the
:data:`flask.session` proxy. The object however itself will provide the
Expand Down

0 comments on commit 6142aa6

Please sign in to comment.