Merge pull request #4165 from yuxiaoy1/patch-1

Change flask.xxx to plain version in testing docs
This commit is contained in:
David Lord 2021-06-21 10:07:33 -07:00 committed by GitHub
commit 49cbb77528
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -225,13 +225,13 @@ temporarily. With this you can access the :class:`~flask.request`,
:class:`~flask.g` and :class:`~flask.session` objects like in view :class:`~flask.g` and :class:`~flask.session` objects like in view
functions. Here is a full example that demonstrates this approach:: functions. Here is a full example that demonstrates this approach::
import flask from flask import Flask, request
app = flask.Flask(__name__) app = Flask(__name__)
with app.test_request_context('/?name=Peter'): with app.test_request_context('/?name=Peter'):
assert flask.request.path == '/' assert request.path == '/'
assert flask.request.args['name'] == 'Peter' assert request.args['name'] == 'Peter'
All the other objects that are context bound can be used in the same All the other objects that are context bound can be used in the same
way. way.
@ -248,7 +248,7 @@ the test request context leaves the ``with`` block. If you do want the
:meth:`~flask.Flask.before_request` functions to be called as well, you :meth:`~flask.Flask.before_request` functions to be called as well, you
need to call :meth:`~flask.Flask.preprocess_request` yourself:: need to call :meth:`~flask.Flask.preprocess_request` yourself::
app = flask.Flask(__name__) app = Flask(__name__)
with app.test_request_context('/?name=Peter'): with app.test_request_context('/?name=Peter'):
app.preprocess_request() app.preprocess_request()
@ -261,7 +261,7 @@ If you want to call the :meth:`~flask.Flask.after_request` functions you
need to call into :meth:`~flask.Flask.process_response` which however need to call into :meth:`~flask.Flask.process_response` which however
requires that you pass it a response object:: requires that you pass it a response object::
app = flask.Flask(__name__) app = Flask(__name__)
with app.test_request_context('/?name=Peter'): with app.test_request_context('/?name=Peter'):
resp = Response('...') resp = Response('...')
@ -330,7 +330,7 @@ context around for a little longer so that additional introspection can
happen. With Flask 0.4 this is possible by using the happen. With Flask 0.4 this is possible by using the
:meth:`~flask.Flask.test_client` with a ``with`` block:: :meth:`~flask.Flask.test_client` with a ``with`` block::
app = flask.Flask(__name__) app = Flask(__name__)
with app.test_client() as c: with app.test_client() as c:
rv = c.get('/?tequila=42') rv = c.get('/?tequila=42')
@ -354,7 +354,7 @@ keep the context around and access :data:`flask.session`::
with app.test_client() as c: with app.test_client() as c:
rv = c.get('/') rv = c.get('/')
assert flask.session['foo'] == 42 assert session['foo'] == 42
This however does not make it possible to also modify the session or to 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 access the session before a request was fired. Starting with Flask 0.8 we