Skip to content

Commit b731fec

Browse files
authored
Fix Flask 3.0 compatibility - remove request_ctx fixture (#168)
1 parent 97d49fd commit b731fec

File tree

6 files changed

+7
-58
lines changed

6 files changed

+7
-58
lines changed

docs/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
Changelog
44
=========
55

6+
UNRELEASED
7+
----------
8+
9+
- Fix compatibility with ``Flask 3.0`` -- the consequence is that the deprecated and incompatible ``request_ctx`` has been removed.
10+
611
1.2.1
712
------------------
813
- Fix bug in ``:meth:pytest_flask.fixtures.live_server``

docs/features.rst

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,28 +188,6 @@ in your project's ``pytest.ini`` file)::
188188
addopts = --live-server-port=5000
189189

190190

191-
``request_ctx`` - request context (Deprecated)
192-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193-
194-
**This fixture is deprecated and will be removed in the future.**
195-
196-
The request context which contains all request relevant information.
197-
198-
.. hint::
199-
200-
The request context has been pushed implicitly any time the ``app``
201-
fixture is applied and is kept around during test execution, so it’s easy
202-
to introspect the data:
203-
204-
.. code:: python
205-
206-
from flask import request, url_for
207-
208-
def test_request_headers(client):
209-
res = client.get(url_for('ping'), headers=[('X-Something', '42')])
210-
assert request.headers['X-Something'] == '42'
211-
212-
213191
``live_server_scope`` - set the scope of the live server
214192
``````````````````````````````````````````````````````````````````
215193

requirements/main.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pytest>=5.2
2-
Flask <3.0
3-
Werkzeug>=0.7
2+
Flask
3+
Werkzeug

src/pytest_flask/fixtures.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import warnings
44

55
import pytest
6-
from flask import _request_ctx_stack
76

87
from ._internal import _determine_scope
98
from ._internal import _make_accept_header
@@ -92,23 +91,6 @@ def config(app):
9291
return app.config
9392

9493

95-
@pytest.fixture
96-
def request_ctx(app):
97-
"""The request context which contains all request relevant information,
98-
e.g. `session`, `g`, `flashes`, etc.
99-
"""
100-
warnings.warn(
101-
"In Werzeug 2.0.0, the Client request methods "
102-
"(client.get, client.post) always return an instance of TestResponse. This "
103-
"class provides a reference to the request object through 'response.request' "
104-
"The fixture 'request_ctx' is deprecated and will be removed in the future, using TestResponse.request "
105-
"is the preferred way.",
106-
DeprecationWarning,
107-
stacklevel=2,
108-
)
109-
return _request_ctx_stack.top
110-
111-
11294
@pytest.fixture(params=["application/json", "text/html"])
11395
def mimetype(request):
11496
return request.param

src/pytest_flask/plugin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from .fixtures import client_class
1616
from .fixtures import config
1717
from .fixtures import live_server
18-
from .fixtures import request_ctx
1918
from .pytest_compat import getfixturevalue
2019

2120

tests/test_fixtures.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,6 @@ def test_accept_json(self, accept_json):
1616
def test_accept_jsonp(self, accept_jsonp):
1717
assert accept_jsonp == [("Accept", "application/json-p")]
1818

19-
def test_request_ctx(self, app, request_ctx):
20-
assert request_ctx.app is app
21-
22-
def test_request_ctx_is_kept_around(self, client):
23-
res = client.get(url_for("index"), headers=[("X-Something", "42")])
24-
"""In werkzeug 2.0.0 the test Client provides a new attribute 'request'
25-
in the response class which holds a reference to the request object that
26-
produced the respective response, making instrospection easier"""
27-
try:
28-
assert res.request.headers["X-Something"] == "42"
29-
except AttributeError:
30-
"""This is the conventional (pre 2.0.0) way of reaching the
31-
request object, using flask.request global."""
32-
assert request.headers["X-Something"] == "42"
33-
3419
def test_accept_mimetype(self, accept_mimetype):
3520
mimestrings = [[("Accept", "application/json")], [("Accept", "text/html")]]
3621
assert accept_mimetype in mimestrings

0 commit comments

Comments
 (0)