testing.rst
This file
Path
docs/testing.rst
319 lines · 10.2 KiB
Last changed by
Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
History of this fileTake it
The walk stopped after 200 commits: lines older than f32f191 point at it.
Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 1–3why, one step back1Testing Flask Applications2==========================3Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 4–6why, one step back4Flask provides utilities for testing an application. This documentation5goes over techniques for working with different parts of the application6in tests.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 7why, one step back7Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 8why, one step back8We will use the `pytest`_ framework to set up and run our tests.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 9why, one step back9Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 10why, one step back10.. code-block:: textMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 11–15why, one step back1112 $ pip install pytest1314.. _pytest: https://docs.pytest.org/15Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 16–19why, one step back16The :doc:`tutorial </tutorial/index>` goes over how to write tests for17100% coverage of the sample Flaskr blog application. See18:doc:`the tutorial on tests </tutorial/tests>` for a detailed19explanation of specific tests for an application.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 20–21why, one step back2021Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 22–23why, one step back22Identifying Tests23-----------------Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 24why, one step back24Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 25–27why, one step back25Tests are typically located in the ``tests`` folder. Tests are functions26that start with ``test_``, in Python modules that start with ``test_``.27Tests can also be further grouped in classes that start with ``Test``.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 28why, one step back28Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 29–32why, one step back29It can be difficult to know what to test. Generally, try to test the30code that you write, not the code of libraries that you use, since they31are already tested. Try to extract complex behaviors as separate32functions to test individually.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 33–34why, one step back3334Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 35–36why, one step back35Fixtures36--------Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 37why, one step back37Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 38–42why, one step back38Pytest *fixtures* allow writing pieces of code that are reusable across39tests. A simple fixture returns a value, but a fixture can also do40setup, yield a value, then do teardown. Fixtures for the application,41test client, and CLI runner are shown below, they can be placed in42``tests/conftest.py``.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 43why, one step back43Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 44–48why, one step back44If you're using an45:doc:`application factory </patterns/appfactories>`, define an ``app``46fixture to create and configure an app instance. You can add code before47and after the ``yield`` to set up and tear down other resources, such as48creating and clearing a database.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 49why, one step back49Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 50–52why, one step back50If you're not using a factory, you already have an app object you can51import and configure directly. You can still use an ``app`` fixture to52set up and tear down resources.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 53why, one step back53Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 54why, one step back54.. code-block:: pythonMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 55why, one step back55Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 56–57why, one step back56 import pytest57 from my_project import create_appMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 58why, one step back58Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 59–64why, one step back59 @pytest.fixture()60 def app():61 app = create_app()62 app.config.update({63 "TESTING": True,64 })Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 65why, one step back65Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 66why, one step back66 # other setup can go hereMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 67why, one step back67Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 68why, one step back68 yield appMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 69why, one step back69Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 70why, one step back70 # clean up / reset resources hereMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 71–72why, one step back7172Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 73–75why, one step back73 @pytest.fixture()74 def client(app):75 return app.test_client()Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 76–77why, one step back7677Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 78–80why, one step back78 @pytest.fixture()79 def runner(app):80 return app.test_cli_runner()Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 81–82why, one step back8182Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 83–84why, one step back83Sending Requests with the Test Client84-------------------------------------Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 85why, one step back85Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 86–89why, one step back86The test client makes requests to the application without running a live87server. Flask's client extends88:doc:`Werkzeug's client <werkzeug:test>`, see those docs for additional89information.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 90why, one step back90Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 91–95why, one step back91The ``client`` has methods that match the common HTTP request methods,92such as ``client.get()`` and ``client.post()``. They take many arguments93for building the request; you can find the full documentation in94:class:`~werkzeug.test.EnvironBuilder`. Typically you'll use ``path``,95``query``, ``headers``, and ``data`` or ``json``.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 96why, one step back96Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 97–102why, one step back97To make a request, call the method the request should use with the path98to the route to test. A :class:`~werkzeug.test.TestResponse` is returned99to examine the response data. It has all the usual properties of a100response object. You'll usually look at ``response.data``, which is the101bytes returned by the view. If you want to use text, Werkzeug 2.1102provides ``response.text``, or use ``response.get_data(as_text=True)``.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 103why, one step back103Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 104why, one step back104.. code-block:: pythonMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 105why, one step back105Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 106–108why, one step back106 def test_request_example(client):107 response = client.get("/posts")108 assert b"<h2>Hello, World!</h2>" in response.dataMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 109–110why, one step back109110Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 111–113why, one step back111Pass a dict ``query={"key": "value", ...}`` to set arguments in the112query string (after the ``?`` in the URL). Pass a dict ``headers={}``113to set request headers.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 114why, one step back114Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 115–117why, one step back115To send a request body in a POST or PUT request, pass a value to116``data``. If raw bytes are passed, that exact body is used. Usually,117you'll pass a dict to set form data.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 118–119why, one step back118119Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 120–121why, one step back120Form Data121~~~~~~~~~Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 122why, one step back122Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 123–125why, one step back123To send form data, pass a dict to ``data``. The ``Content-Type`` header124will be set to ``multipart/form-data`` or125``application/x-www-form-urlencoded`` automatically.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 126why, one step back126Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 127–131why, one step back127If a value is a file object opened for reading bytes (``"rb"`` mode), it128will be treated as an uploaded file. To change the detected filename and129content type, pass a ``(file, filename, content_type)`` tuple. File130objects will be closed after making the request, so they do not need to131use the usual ``with open() as f:`` pattern.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 132why, one step back132Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 133–134why, one step back133It can be useful to store files in a ``tests/resources`` folder, then134use ``pathlib.Path`` to get files relative to the current test file.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 135why, one step back135Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 136why, one step back136.. code-block:: pythonMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 137why, one step back137Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 138why, one step back138 from pathlib import PathMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 139why, one step back139Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 140–141why, one step back140 # get the resources folder in the tests folder141 resources = Path(__file__).parent / "resources"Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 142why, one step back142Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 143–149why, one step back143 def test_edit_user(client):144 response = client.post("/user/2/edit", data={145 name="Flask",146 theme="dark",147 picture=(resources / "picture.png").open("rb"),148 })149 assert response.status_code == 200Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 150–151why, one step back150151Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 152–153why, one step back152JSON Data153~~~~~~~~~Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 154why, one step back154Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 155–156why, one step back155To send JSON data, pass an object to ``json``. The ``Content-Type``156header will be set to ``application/json`` automatically.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 157why, one step back157Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 158–159why, one step back158Similarly, if the response contains JSON data, the ``response.json``159attribute will contain the deserialized object.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 160why, one step back160Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 161why, one step back161.. code-block:: pythonMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 162why, one step back162Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 163–176why, one step back163 def test_json_data(client):164 response = client.post("/graphql", json={165 "query": """166 query User($id: String!) {167 user(id: $id) {168 name169 theme170 picture_url171 }172 }173 """,174 variables={"id": 2},175 })176 assert response.json["data"]["user"]["name"] == "Flask"Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 177–178why, one step back177178Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 179–180why, one step back179Following Redirects180-------------------Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 181why, one step back181Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 182–185why, one step back182By default, the client does not make additional requests if the response183is a redirect. By passing ``follow_redirects=True`` to a request method,184the client will continue to make requests until a non-redirect response185is returned.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 186why, one step back186Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 187–190why, one step back187:attr:`TestResponse.history <werkzeug.test.TestResponse.history>` is188a tuple of the responses that led up to the final response. Each189response has a :attr:`~werkzeug.test.TestResponse.request` attribute190which records the request that produced that response.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 191why, one step back191Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 192why, one step back192.. code-block:: pythonMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 193why, one step back193Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 194–199why, one step back194 def test_logout_redirect(client):195 response = client.get("/logout")196 # Check that there was one redirect response.197 assert len(response.history) == 1198 # Check that the second request was to the index page.199 assert response.request.path == "/index"Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 200–201why, one step back200201Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 202–203why, one step back202Accessing and Modifying the Session203-----------------------------------Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 204why, one step back204Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 205–208why, one step back205To access Flask's context variables, mainly206:data:`~flask.session`, use the client in a ``with`` statement.207The app and request context will remain active *after* making a request,208until the ``with`` block ends.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 209why, one step back209Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 210why, one step back210.. code-block:: pythonMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 211why, one step back211Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 212why, one step back212 from flask import sessionMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 213why, one step back213Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 214–218why, one step back214 def test_access_session(client):215 with client:216 client.post("/auth/login", data={"username": "flask"})217 # session is still accessible218 assert session["user_id"] == 1Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 219why, one step back219Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 220why, one step back220 # session is no longer accessibleMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 221why, one step back221Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 222–226why, one step back222If you want to access or set a value in the session *before* making a223request, use the client's224:meth:`~flask.testing.FlaskClient.session_transaction` method in a225``with`` statement. It returns a session object, and will save the226session once the block ends.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 227why, one step back227Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 228why, one step back228.. code-block:: pythonMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 229why, one step back229Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 230why, one step back230 from flask import sessionMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 231why, one step back231Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 232–235why, one step back232 def test_modify_session(client):233 with client.session_transaction() as session:234 # set a user id without going through the login route235 session["user_id"] = 1Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 236why, one step back236Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 237why, one step back237 # session is saved nowMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 238why, one step back238Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 239–240why, one step back239 response = client.get("/users/me")240 assert response.json["username"] == "flask"Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 241–242why, one step back241242Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 243why, one step back243.. _testing-cli:Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 244why, one step back244Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 245–246why, one step back245Running Commands with the CLI Runner246------------------------------------Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 247why, one step back247Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 248–252why, one step back248Flask provides :meth:`~flask.Flask.test_cli_runner` to create a249:class:`~flask.testing.FlaskCliRunner`, which runs CLI commands in250isolation and captures the output in a :class:`~click.testing.Result`251object. Flask's runner extends :doc:`Click's runner <click:testing>`,252see those docs for additional information.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 253why, one step back253Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 254–256why, one step back254Use the runner's :meth:`~flask.testing.FlaskCliRunner.invoke` method to255call commands in the same way they would be called with the ``flask``256command from the command line.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 257why, one step back257Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 258why, one step back258.. code-block:: pythonMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 259why, one step back259Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 260why, one step back260 import clickMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 261why, one step back261Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 262–265why, one step back262 @app.cli.command("hello")263 @click.option("--name", default="World")264 def hello_command(name):265 click.echo(f"Hello, {name}!")Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 266why, one step back266Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 267–269why, one step back267 def test_hello_command(runner):268 result = runner.invoke(["hello"])269 assert "World" in result.outputMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 270why, one step back270Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 271–272why, one step back271 result = runner.invoke(["hello", "--name", "Flask"])272 assert "Flask" in result.outputMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
lines 273–274why, one step back273274Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 275–276why, one step back275Tests that depend on an Active Context276--------------------------------------Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 277why, one step back277Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 278–283why, one step back278You may have functions that are called from views or commands, that279expect an active :doc:`application context </appcontext>` or280:doc:`request context </reqcontext>` because they access ``request``,281``session``, or ``current_app``. Rather than testing them by making a282request or invoking the command, you can create and activate a context283directly.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 284why, one step back284Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 285–287why, one step back285Use ``with app.app_context()`` to push an application context. For286example, database extensions usually require an active app context to287make queries.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 288why, one step back288Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 289why, one step back289.. code-block:: pythonMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 290why, one step back290Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 291–293why, one step back291 def test_db_post_model(app):292 with app.app_context():293 post = db.session.query(Post).get(1)Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 294why, one step back294Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 295–296why, one step back295Use ``with app.test_request_context()`` to push a request context. It296takes the same arguments as the test client's request methods.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 297why, one step back297Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 298why, one step back298.. code-block:: pythonMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 299why, one step back299Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 300–305why, one step back300 def test_validate_user_edit(app):301 with app.test_request_context(302 "/user/2/edit", method="POST", data={"name": ""}303 ):304 # call a function that accesses `request`305 messages = validate_edit_user()Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 306why, one step back306Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 307why, one step back307 assert messages["name"][0] == "Name cannot be empty."Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 308why, one step back308Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 309–312why, one step back309Creating a test request context doesn't run any of the Flask dispatching310code, so ``before_request`` functions are not called. If you need to311call these, usually it's better to make a full request instead. However,312it's possible to call them manually.Merge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 313why, one step back313Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
line 314why, one step back314.. code-block:: pythonMerge pull request #3691 from greyli/update-discord-linksGrey Libefore adoptionf32f191
line 315why, one step back315Merge branch '2.0.x'David Lordbefore adoptionb6a8ccd
lines 316–319why, one step back316 def test_auth_token(app):317 with app.test_request_context("/user/2/edit", headers={"X-Auth-Token": "1"}):318 app.preprocess_request()319 assert g.user.name == "Flask"