7. Test Client¶
FlaskClient(application, response_wrapper=None, use_cookies=True, allow_subdomain_redirects=False)¶
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 a
withstatement. For general information about how to use this class refer to
Basic usage is outlined in the 1 Testing Flask Applications chapter.
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 the
withblock 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.