Skip to content
Myr

Added example for context bound objects to the testing docs. This fixes #18

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent a9284af · Browse files · 1 file+19 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+19 added−0 removed

  • other:+19 added−0 removed

1 file+19 added−0 removed

modified:docs/testing.rst+19 added
193 unmodified lines
194195196.. _MiniTwit Example:197 http://github.com/mitsuhiko/flask/tree/master/examples/minitwit/198199200Other Testing Tricks201--------------------202203Besides using the test client we used above there is also the204:meth:`~flask.Flask.test_request_context` method that in combination with205the `with` statement can be used to activate a request context206temporarily. With that you can access the :class:`~flask.request`,207:class:`~flask.g` and :class:`~flask.session` objects like in view208functions. Here a full example that showcases this::209210 app = flask.Flask(__name__)211212 with app.test_request_context('/?name=Peter'):213 assert flask.request.path == '/'214 assert flask.request.args['name'] == 'Peter'215216All the other objects that are context bound can be used the same.