7. Test Client¶
-
class
flask.testing.FlaskClient(application, response_wrapper=None, use_cookies=True, allow_subdomain_redirects=False)[source]¶ Works like a regular Werkzeug test client but has some knowledge about how Flask works to defer the cleanup of the request context stack to the end of a
withbody when used in awithstatement. For general information about how to use this class refer towerkzeug.test.Client.Basic usage is outlined in the 1 Testing Flask Applications chapter.
-
session_transaction(*args, **kwds)[source]¶ When used in combination with a
withstatement this opens a session transaction. This can be used to modify the session that the test client uses. Once thewithblock 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.
-