tests.custom_flask_client.CustomFlaskClient.session_transaction

CustomFlaskClient.session_transaction(*args: Any, **kwargs: Any) Generator[flask.sessions.SessionMixin, None, None]

When used in combination with a with statement this opens a session transaction. This can be used to modify the session that the test client uses. Once the with block is left the session is stored back.

with client.session_transaction() as session:
    session['value'] = 42

Internally this is implemented by going through a temporary test request context and since session handling could depend on request variables this function accepts the same arguments as test_request_context() which are directly passed through.