Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Changelog
=========

UNRELEASED
----------

- Fix compatibility with ``Flask 3.0`` -- the consequence is that the deprecated and incompatible ``request_ctx`` has been removed.

1.2.1
------------------
- Fix bug in ``:meth:pytest_flask.fixtures.live_server``
Expand Down
22 changes: 0 additions & 22 deletions docs/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,28 +188,6 @@ in your project's ``pytest.ini`` file)::
addopts = --live-server-port=5000


``request_ctx`` - request context (Deprecated)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**This fixture is deprecated and will be removed in the future.**

The request context which contains all request relevant information.

.. hint::

The request context has been pushed implicitly any time the ``app``
fixture is applied and is kept around during test execution, so it’s easy
to introspect the data:

.. code:: python

from flask import request, url_for

def test_request_headers(client):
res = client.get(url_for('ping'), headers=[('X-Something', '42')])
assert request.headers['X-Something'] == '42'


``live_server_scope`` - set the scope of the live server
``````````````````````````````````````````````````````````````````

Expand Down
4 changes: 2 additions & 2 deletions requirements/main.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pytest>=5.2
Flask <3.0
Werkzeug>=0.7
Flask
Werkzeug
18 changes: 0 additions & 18 deletions src/pytest_flask/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import warnings

import pytest
from flask import _request_ctx_stack

from ._internal import _determine_scope
from ._internal import _make_accept_header
Expand Down Expand Up @@ -92,23 +91,6 @@ def config(app):
return app.config


@pytest.fixture
def request_ctx(app):
"""The request context which contains all request relevant information,
e.g. `session`, `g`, `flashes`, etc.
"""
warnings.warn(
"In Werzeug 2.0.0, the Client request methods "
"(client.get, client.post) always return an instance of TestResponse. This "
"class provides a reference to the request object through 'response.request' "
"The fixture 'request_ctx' is deprecated and will be removed in the future, using TestResponse.request "
"is the preferred way.",
DeprecationWarning,
stacklevel=2,
)
return _request_ctx_stack.top


@pytest.fixture(params=["application/json", "text/html"])
def mimetype(request):
return request.param
Expand Down
1 change: 0 additions & 1 deletion src/pytest_flask/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from .fixtures import client_class
from .fixtures import config
from .fixtures import live_server
from .fixtures import request_ctx
from .pytest_compat import getfixturevalue


Expand Down
15 changes: 0 additions & 15 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@ def test_accept_json(self, accept_json):
def test_accept_jsonp(self, accept_jsonp):
assert accept_jsonp == [("Accept", "application/json-p")]

def test_request_ctx(self, app, request_ctx):
assert request_ctx.app is app

def test_request_ctx_is_kept_around(self, client):
res = client.get(url_for("index"), headers=[("X-Something", "42")])
"""In werkzeug 2.0.0 the test Client provides a new attribute 'request'
in the response class which holds a reference to the request object that
produced the respective response, making instrospection easier"""
try:
assert res.request.headers["X-Something"] == "42"
except AttributeError:
"""This is the conventional (pre 2.0.0) way of reaching the
request object, using flask.request global."""
assert request.headers["X-Something"] == "42"

def test_accept_mimetype(self, accept_mimetype):
mimestrings = [[("Accept", "application/json")], [("Accept", "text/html")]]
assert accept_mimetype in mimestrings
Expand Down