From 1b8b9fa98622ba13bb774f1e1e6f280dc08777bb Mon Sep 17 00:00:00 2001 From: jeff levesque Date: Wed, 20 Jul 2016 23:57:09 -0400 Subject: [PATCH 01/33] #45: features.rst, add 'HTTP Request' section --- docs/features.rst | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/docs/features.rst b/docs/features.rst index 10e97b0..61bb0c4 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -194,6 +194,74 @@ The request context which contains all request relevant information. assert request.headers['X-Something'] == '42' +HTTP Request +~~~~~~~~~~~~~~~~~~~ + +Common request methods are available through the internals of the `Flask API`_. +Specifically, the API creates the default `flask.Flask.test_client`_ instance, +which works like a regular `Werkzeug test client`_. + +Example: + +.. code:: python + + def test_post_request(client, live_server): + @live_server.app.route('/load-data') + def get_endpoint(): + return url_for('name.load', _external=True) + + live_server.start() + + res = client.post( + get_endpoint(), + headers={'Content-Type': 'application/json'}, + data={'key1': 'value1', 'key2': 'value2'} + ) + + assert res.status_code == 200 + +Example: + +.. code:: python + + def test_get_request(client, live_server): + @live_server.app.route('/load-data') + def get_endpoint(): + return url_for('name.load', _external=True) + + live_server.start() + + res = client.get(get_endpoint()) + + assert res.status_code == 200 + +.. note:: + + The notation ``name.load_data``, should correspond to a ``endpoint='load'`` + attribute, within a route decorator. The following is a route decorator + using the `blueprint`_ implementation: + + .. code:: python + from flask import Blueprint, request + + # local variables + blueprint = Blueprint( + 'name', + __name__, + template_folder='interface/templates', + static_folder='interface/static' + ) + + @blueprint.route('/load-data', methods=['POST'], endpoint='load') + def load_data(): + + if request.method == 'POST': + + # get data + if request.get_json(): + + ... + Content negotiation ~~~~~~~~~~~~~~~~~~~ @@ -272,3 +340,6 @@ on `what markers are`_ and for notes on `using them`_. .. _Selenium: http://www.seleniumhq.org .. _what markers are: http://pytest.org/latest/mark.html .. _using them: http://pytest.org/latest/example/markers.html#marking-whole-classes-or-modules +.. _Flask API: https://pytest-flask.readthedocs.io/en/latest/features.html#client-application-test-client +.. _Werkzeug test client: http://werkzeug.pocoo.org/docs/0.11/test/#werkzeug.test.Client +.. _blueprint: http://flask.pocoo.org/docs/0.11/blueprints/ From 440c793719baa0c86d63f2468b20a804cc5317cd Mon Sep 17 00:00:00 2001 From: jeff levesque Date: Thu, 21 Jul 2016 07:14:27 -0400 Subject: [PATCH 02/33] #45: features.rst, provide alternative, self contained example --- docs/features.rst | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/features.rst b/docs/features.rst index 61bb0c4..5b34387 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -237,7 +237,7 @@ Example: .. note:: - The notation ``name.load_data``, should correspond to a ``endpoint='load'`` + The notation ``name.load_data``, corresponds to a ``endpoint='load'`` attribute, within a route decorator. The following is a route decorator using the `blueprint`_ implementation: @@ -262,6 +262,25 @@ Example: ... +Alternatively, the route function can be referenced directly from the +``live_server`` implementation, rather than implementing an ``endpoint``: + + .. code:: python + def test_load_data(live_server, client): + @live_server.app.route('/load-data', methods=['POST']) + def load_data(): + pass + + live_server.start() + + res = client.post(url_for('load_data'), data={}) + assert res.status_code == 200 + +.. note:: + + Remember to explicitly define which ``methods`` are supported when + registering the above route function. + Content negotiation ~~~~~~~~~~~~~~~~~~~ From b2366f4cd96209f181a3eae82f5715b32c5aea27 Mon Sep 17 00:00:00 2001 From: jeff levesque Date: Thu, 21 Jul 2016 07:15:49 -0400 Subject: [PATCH 03/33] #45: features.rst, remove dummy data --- docs/features.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/features.rst b/docs/features.rst index 5b34387..3cbfe2c 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -215,7 +215,7 @@ Example: res = client.post( get_endpoint(), headers={'Content-Type': 'application/json'}, - data={'key1': 'value1', 'key2': 'value2'} + data={} ) assert res.status_code == 200 From 8f2f2c56f2730105a08db50e08aa06f8dfebd35e Mon Sep 17 00:00:00 2001 From: jeff levesque Date: Thu, 21 Jul 2016 07:17:45 -0400 Subject: [PATCH 04/33] #45: features.rst, add newline at start of code example --- docs/features.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/features.rst b/docs/features.rst index 3cbfe2c..84312a8 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -242,6 +242,7 @@ Example: using the `blueprint`_ implementation: .. code:: python + from flask import Blueprint, request # local variables @@ -266,6 +267,7 @@ Alternatively, the route function can be referenced directly from the ``live_server`` implementation, rather than implementing an ``endpoint``: .. code:: python + def test_load_data(live_server, client): @live_server.app.route('/load-data', methods=['POST']) def load_data(): From 2b9c74548e0b5361e24ad35093a3a6dab621ed04 Mon Sep 17 00:00:00 2001 From: jeff levesque Date: Thu, 21 Jul 2016 07:19:49 -0400 Subject: [PATCH 05/33] #45: features.rst, reduce example syntax --- docs/features.rst | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/features.rst b/docs/features.rst index 84312a8..b777fed 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -255,13 +255,9 @@ Example: @blueprint.route('/load-data', methods=['POST'], endpoint='load') def load_data(): - if request.method == 'POST': - - # get data if request.get_json(): - - ... + pass Alternatively, the route function can be referenced directly from the ``live_server`` implementation, rather than implementing an ``endpoint``: From 08331f5b8105a7f836ff78f55c43e942f3e27ff5 Mon Sep 17 00:00:00 2001 From: northernSage Date: Wed, 10 Feb 2021 12:10:23 -0300 Subject: [PATCH 06/33] update coverage run instructions to use pytest-cov --- CONTRIBUTING.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index f31a115..4cefa22 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -99,12 +99,11 @@ Checking Test Coverage ~~~~~~~~~~~~~~~~~~~~~~~ To get a complete report of code sections not being touched by the -test suite run ``pytest`` using ``coverage``. +test suite run ``pytest`` using ``pytest-cov``. .. code-block:: text - $ coverage run -m pytest - $ coverage html + $ pytest --cov=pytest_flask/ --cov-report=html Open ``htmlcov/index.html`` in your browser. From 5e00acbaac13082faf10a0402cc0ea7b3675cb54 Mon Sep 17 00:00:00 2001 From: northernSage Date: Wed, 10 Feb 2021 12:51:31 -0300 Subject: [PATCH 07/33] add changelog entry --- docs/changelog.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 21e36d2..da79cf6 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -3,6 +3,12 @@ Changelog ========= +1.1.1 (2020-11-08) +------------------ + +- Remove deprecated ``:meth:live_server.url`` + + 1.1.0 (2020-11-08) ------------------ From f7adf17dfacbe7f96fd8017791f576025247f58d Mon Sep 17 00:00:00 2001 From: northernSage Date: Wed, 10 Feb 2021 13:11:24 -0300 Subject: [PATCH 08/33] use pytest command instead of py.test --- docs/tutorial.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 315bde1..f66b4f0 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -31,9 +31,9 @@ Define your application fixture in ``conftest.py``: Step 3. Run your test suite --------------------------- -Use the ``py.test`` command to run your test suite:: +Use the ``pytest`` command to run your test suite:: - py.test + pytest .. note:: Test discovery. From 41178101616809cc161724efa7801c2390e94da8 Mon Sep 17 00:00:00 2001 From: northernSage Date: Wed, 10 Feb 2021 13:36:51 -0300 Subject: [PATCH 09/33] move deprecation decorator to new _internal.py module --- pytest_flask/_internal.py | 19 +++++++++++++++++++ pytest_flask/fixtures.py | 19 +------------------ 2 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 pytest_flask/_internal.py diff --git a/pytest_flask/_internal.py b/pytest_flask/_internal.py new file mode 100644 index 0000000..caedd18 --- /dev/null +++ b/pytest_flask/_internal.py @@ -0,0 +1,19 @@ +import functools +import warnings + + +def deprecated(reason): + """Decorator which can be used to mark function or method as deprecated. + It will result a warning being emmitted when the function is called.""" + + def decorator(func): + @functools.wraps(func) + def deprecated_call(*args, **kwargs): + warnings.simplefilter("always", DeprecationWarning) + warnings.warn(reason, DeprecationWarning, stacklevel=2) + warnings.simplefilter("default", DeprecationWarning) + return func(*args, **kwargs) + + return deprecated_call + + return decorator diff --git a/pytest_flask/fixtures.py b/pytest_flask/fixtures.py index fc3326a..49eaa4e 100755 --- a/pytest_flask/fixtures.py +++ b/pytest_flask/fixtures.py @@ -6,28 +6,11 @@ import signal import socket import time -import warnings import pytest from flask import _request_ctx_stack - -def deprecated(reason): - """Decorator which can be used to mark function or method as deprecated. - It will result a warning being emmitted when the function is called. - """ - - def decorator(func): - @functools.wraps(func) - def deprecated_call(*args, **kwargs): - warnings.simplefilter("always", DeprecationWarning) - warnings.warn(reason, DeprecationWarning, stacklevel=2) - warnings.simplefilter("default", DeprecationWarning) - return func(*args, **kwargs) - - return deprecated_call - - return decorator +from ._internal import deprecated @pytest.fixture From 0f98eac533936b7ea8b464bb5aa70f3893019696 Mon Sep 17 00:00:00 2001 From: northernSage Date: Wed, 10 Feb 2021 13:55:36 -0300 Subject: [PATCH 10/33] update pre-commit hooks --- .pre-commit-config.yaml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7d6cfc3..aa5cd4c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 + rev: v3.4.0 hooks: - id: check-byte-order-marker - id: trailing-whitespace @@ -9,7 +9,7 @@ repos: args: [--remove] - id: check-yaml - repo: https://github.com/asottile/reorder_python_imports - rev: v2.3.5 + rev: v2.4.0 hooks: - id: reorder-python-imports args: ['--application-directories=.:src', --py3-plus] @@ -18,7 +18,7 @@ repos: hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.3 + rev: 3.8.4 hooks: - id: flake8 additional_dependencies: [flake8-bugbear] @@ -30,3 +30,7 @@ repos: files: ^(HOWTORELEASE.rst|README.rst)$ language: python additional_dependencies: [pygments, restructuredtext_lint] +- repo: https://github.com/myint/autoflake.git + rev: v1.4 + hooks: + - id: autoflake From 587adc9e2dbf629c3976ba3964bc688e776f2f73 Mon Sep 17 00:00:00 2001 From: northernSage Date: Wed, 10 Feb 2021 14:18:18 -0300 Subject: [PATCH 11/33] move LiveServer class from fixtures.py to a separate module --- pytest_flask/fixtures.py | 135 +++++------------------------------- pytest_flask/live_server.py | 105 ++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 118 deletions(-) create mode 100644 pytest_flask/live_server.py diff --git a/pytest_flask/fixtures.py b/pytest_flask/fixtures.py index 49eaa4e..c5010be 100755 --- a/pytest_flask/fixtures.py +++ b/pytest_flask/fixtures.py @@ -1,16 +1,26 @@ #!/usr/bin/env python -import functools -import logging -import multiprocessing -import os -import signal import socket -import time import pytest from flask import _request_ctx_stack -from ._internal import deprecated +from .live_server import LiveServer + + +def _rewrite_server_name(server_name, new_port): + """Rewrite server port in ``server_name`` with ``new_port`` value.""" + sep = ":" + if sep in server_name: + server_name, port = server_name.split(sep, 1) + return sep.join((server_name, new_port)) + + +def determine_scope(*, fixture_name, config): + return config.getini("live_server_scope") + + +def _make_accept_header(mimetype): + return [("Accept", mimetype)] @pytest.fixture @@ -41,113 +51,6 @@ def test_login(self): request.cls.client = client -class LiveServer: - """The helper class used to manage a live server. Handles creation and - stopping application in a separate process. - - :param app: The application to run. - :param host: The host where to listen (default localhost). - :param port: The port to run application. - :param wait: The timeout after which test case is aborted if - application is not started. - """ - - def __init__(self, app, host, port, wait, clean_stop=False): - self.app = app - self.port = port - self.host = host - self.wait = wait - self.clean_stop = clean_stop - self._process = None - - def start(self): - """Start application in a separate process.""" - - def worker(app, host, port): - app.run(host=host, port=port, use_reloader=False, threaded=True) - - self._process = multiprocessing.Process( - target=worker, args=(self.app, self.host, self.port) - ) - self._process.daemon = True - self._process.start() - - keep_trying = True - start_time = time.time() - while keep_trying: - elapsed_time = time.time() - start_time - if elapsed_time > self.wait: - pytest.fail( - "Failed to start the server after {!s} " - "seconds.".format(self.wait) - ) - if self._is_ready(): - keep_trying = False - - def _is_ready(self): - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - try: - sock.connect((self.host, self.port)) - except socket.error: - ret = False - else: - ret = True - finally: - sock.close() - return ret - - @deprecated( - reason=( - 'The "live_server.url" method is deprecated and will ' - "be removed in the future. Please use " - 'the "flask.url_for" function instead.', - ) - ) - def url(self, url=""): - """Returns the complete url based on server options.""" - return "http://{host!s}:{port!s}{url!s}".format( - host=self.host, port=self.port, url=url - ) - - def stop(self): - """Stop application process.""" - if self._process: - if self.clean_stop and self._stop_cleanly(): - return - if self._process.is_alive(): - # If it's still alive, kill it - self._process.terminate() - - def _stop_cleanly(self, timeout=5): - """Attempts to stop the server cleanly by sending a SIGINT signal and waiting for - ``timeout`` seconds. - - :return: True if the server was cleanly stopped, False otherwise. - """ - try: - os.kill(self._process.pid, signal.SIGINT) - self._process.join(timeout) - return True - except Exception as ex: - logging.error("Failed to join the live server process: %r", ex) - return False - - def __repr__(self): - return "" % self.url() - - -def _rewrite_server_name(server_name, new_port): - """Rewrite server port in ``server_name`` with ``new_port`` value.""" - sep = ":" - if sep in server_name: - server_name, port = server_name.split(sep, 1) - return sep.join((server_name, new_port)) - - -def determine_scope(*, fixture_name, config): - return config.getini("live_server_scope") - - @pytest.fixture(scope=determine_scope) def live_server(request, app, pytestconfig): """Run application in a separate process. @@ -214,10 +117,6 @@ def mimetype(request): return request.param -def _make_accept_header(mimetype): - return [("Accept", mimetype)] - - @pytest.fixture def accept_mimetype(mimetype): return _make_accept_header(mimetype) diff --git a/pytest_flask/live_server.py b/pytest_flask/live_server.py new file mode 100644 index 0000000..9a8f8ee --- /dev/null +++ b/pytest_flask/live_server.py @@ -0,0 +1,105 @@ +import logging +import multiprocessing +import os +import signal +import socket +import time + +import pytest + +from ._internal import deprecated + + +class LiveServer: + """The helper class used to manage a live server. Handles creation and + stopping application in a separate process. + + :param app: The application to run. + :param host: The host where to listen (default localhost). + :param port: The port to run application. + :param wait: The timeout after which test case is aborted if + application is not started. + """ + + def __init__(self, app, host, port, wait, clean_stop=False): + self.app = app + self.port = port + self.host = host + self.wait = wait + self.clean_stop = clean_stop + self._process = None + + def start(self): + """Start application in a separate process.""" + + def worker(app, host, port): + app.run(host=host, port=port, use_reloader=False, threaded=True) + + self._process = multiprocessing.Process( + target=worker, args=(self.app, self.host, self.port) + ) + self._process.daemon = True + self._process.start() + + keep_trying = True + start_time = time.time() + while keep_trying: + elapsed_time = time.time() - start_time + if elapsed_time > self.wait: + pytest.fail( + "Failed to start the server after {!s} " + "seconds.".format(self.wait) + ) + if self._is_ready(): + keep_trying = False + + def _is_ready(self): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + try: + sock.connect((self.host, self.port)) + except socket.error: + ret = False + else: + ret = True + finally: + sock.close() + return ret + + @deprecated( + reason=( + 'The "live_server.url" method is deprecated and will ' + "be removed in the future. Please use " + 'the "flask.url_for" function instead.', + ) + ) + def url(self, url=""): + """Returns the complete url based on server options.""" + return "http://{host!s}:{port!s}{url!s}".format( + host=self.host, port=self.port, url=url + ) + + def stop(self): + """Stop application process.""" + if self._process: + if self.clean_stop and self._stop_cleanly(): + return + if self._process.is_alive(): + # If it's still alive, kill it + self._process.terminate() + + def _stop_cleanly(self, timeout=5): + """Attempts to stop the server cleanly by sending a SIGINT signal and waiting for + ``timeout`` seconds. + + :return: True if the server was cleanly stopped, False otherwise. + """ + try: + os.kill(self._process.pid, signal.SIGINT) + self._process.join(timeout) + return True + except Exception as ex: + logging.error("Failed to join the live server process: %r", ex) + return False + + def __repr__(self): + return "" % self.url() From b516d0a58e9b0ca6da44548b58f2ce4f0fcfc88c Mon Sep 17 00:00:00 2001 From: northernSage Date: Wed, 10 Feb 2021 14:27:12 -0300 Subject: [PATCH 12/33] move helper functions to _internal.py --- pytest_flask/_internal.py | 16 ++++++++++++++++ pytest_flask/fixtures.py | 21 ++++----------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/pytest_flask/_internal.py b/pytest_flask/_internal.py index caedd18..f5c2c31 100644 --- a/pytest_flask/_internal.py +++ b/pytest_flask/_internal.py @@ -17,3 +17,19 @@ def deprecated_call(*args, **kwargs): return deprecated_call return decorator + + +def _rewrite_server_name(server_name, new_port): + """Rewrite server port in ``server_name`` with ``new_port`` value.""" + sep = ":" + if sep in server_name: + server_name, port = server_name.split(sep, 1) + return sep.join((server_name, new_port)) + + +def _determine_scope(*, fixture_name, config): + return config.getini("live_server_scope") + + +def _make_accept_header(mimetype): + return [("Accept", mimetype)] diff --git a/pytest_flask/fixtures.py b/pytest_flask/fixtures.py index c5010be..8563300 100755 --- a/pytest_flask/fixtures.py +++ b/pytest_flask/fixtures.py @@ -4,25 +4,12 @@ import pytest from flask import _request_ctx_stack +from ._internal import _determine_scope +from ._internal import _make_accept_header +from ._internal import _rewrite_server_name from .live_server import LiveServer -def _rewrite_server_name(server_name, new_port): - """Rewrite server port in ``server_name`` with ``new_port`` value.""" - sep = ":" - if sep in server_name: - server_name, port = server_name.split(sep, 1) - return sep.join((server_name, new_port)) - - -def determine_scope(*, fixture_name, config): - return config.getini("live_server_scope") - - -def _make_accept_header(mimetype): - return [("Accept", mimetype)] - - @pytest.fixture def client(app): """A Flask test client. An instance of :class:`flask.testing.TestClient` @@ -51,7 +38,7 @@ def test_login(self): request.cls.client = client -@pytest.fixture(scope=determine_scope) +@pytest.fixture(scope=_determine_scope) def live_server(request, app, pytestconfig): """Run application in a separate process. From 831910af9379cc5961e880c01407a1d9deb55748 Mon Sep 17 00:00:00 2001 From: northernSage Date: Wed, 10 Feb 2021 15:44:05 -0300 Subject: [PATCH 13/33] update tox.ini and coverage instructions to include imports --- CONTRIBUTING.rst | 5 +++-- tox.ini | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 4cefa22..f31a115 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -99,11 +99,12 @@ Checking Test Coverage ~~~~~~~~~~~~~~~~~~~~~~~ To get a complete report of code sections not being touched by the -test suite run ``pytest`` using ``pytest-cov``. +test suite run ``pytest`` using ``coverage``. .. code-block:: text - $ pytest --cov=pytest_flask/ --cov-report=html + $ coverage run -m pytest + $ coverage html Open ``htmlcov/index.html`` in your browser. diff --git a/tox.ini b/tox.ini index abe2314..c911bc4 100644 --- a/tox.ini +++ b/tox.ini @@ -39,6 +39,12 @@ commands = -ra \ {posargs:tests} +[coverage:report] +omit = + */venv/* + */tmp/* + */tests/* + [testenv:pre] pip_pre=true usedevelop = {[testenv]usedevelop} From c4c31919192dda9f47b91c068f1693e57dfca21e Mon Sep 17 00:00:00 2001 From: northernSage Date: Thu, 11 Feb 2021 10:09:11 -0300 Subject: [PATCH 14/33] ommit unused port variable --- pytest_flask/_internal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_flask/_internal.py b/pytest_flask/_internal.py index f5c2c31..4b44fb9 100644 --- a/pytest_flask/_internal.py +++ b/pytest_flask/_internal.py @@ -23,7 +23,7 @@ def _rewrite_server_name(server_name, new_port): """Rewrite server port in ``server_name`` with ``new_port`` value.""" sep = ":" if sep in server_name: - server_name, port = server_name.split(sep, 1) + server_name, _ = server_name.split(sep, 1) return sep.join((server_name, new_port)) From 1323b9e1e35eaf01069b1d1a461246b52dd7b66a Mon Sep 17 00:00:00 2001 From: northernSage Date: Thu, 11 Feb 2021 10:10:08 -0300 Subject: [PATCH 15/33] move json response tests to separate module --- tests/test_fixtures.py | 33 --------------------------------- tests/test_json_response.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 33 deletions(-) create mode 100644 tests/test_json_response.py diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 2d86c0c..28ca31f 100755 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python import pytest from flask import request from flask import url_for @@ -25,38 +24,6 @@ def test_request_ctx_is_kept_around(self, client): assert request.headers["X-Something"] == "42" -class TestJSONResponse: - def test_json_response(self, client, accept_json): - res = client.get(url_for("ping"), headers=accept_json) - assert res.json == {"ping": "pong"} - - def test_json_response_compare_to_status_code(self, client, accept_json): - assert client.get(url_for("ping"), headers=accept_json) == 200 - assert client.get("fake-route", headers=accept_json) == 404 - assert client.get("fake-route", headers=accept_json) != "404" - res = client.get(url_for("ping"), headers=accept_json) - assert res == res - - def test_mismatching_eq_comparison(self, client, accept_json): - with pytest.raises(AssertionError, match=r"Mismatch in status code"): - assert client.get("fake-route", headers=accept_json) == 200 - with pytest.raises(AssertionError, match=r"404 NOT FOUND"): - assert client.get("fake-route", headers=accept_json) == "200" - - def test_dont_rewrite_existing_implementation(self, app, accept_json): - class MyResponse(app.response_class): - @property - def json(self): - """What is the meaning of life, the universe and everything?""" - return 42 - - app.response_class = MyResponse - client = app.test_client() - - res = client.get(url_for("ping"), headers=accept_json) - assert res.json == 42 - - @pytest.mark.usefixtures("client_class") class TestClientClass: def test_client_attribute(self): diff --git a/tests/test_json_response.py b/tests/test_json_response.py new file mode 100644 index 0000000..ecef59c --- /dev/null +++ b/tests/test_json_response.py @@ -0,0 +1,34 @@ +import pytest +from flask import url_for + + +class TestJSONResponse: + def test_json_response(self, client, accept_json): + res = client.get(url_for("ping"), headers=accept_json) + assert res.json == {"ping": "pong"} + + def test_json_response_compare_to_status_code(self, client, accept_json): + assert client.get(url_for("ping"), headers=accept_json) == 200 + assert client.get("fake-route", headers=accept_json) == 404 + assert client.get("fake-route", headers=accept_json) != "404" + res = client.get(url_for("ping"), headers=accept_json) + assert res == res + + def test_mismatching_eq_comparison(self, client, accept_json): + with pytest.raises(AssertionError, match=r"Mismatch in status code"): + assert client.get("fake-route", headers=accept_json) == 200 + with pytest.raises(AssertionError, match=r"404 NOT FOUND"): + assert client.get("fake-route", headers=accept_json) == "200" + + def test_dont_rewrite_existing_implementation(self, app, accept_json): + class MyResponse(app.response_class): + @property + def json(self): + """What is the meaning of life, the universe and everything?""" + return 42 + + app.response_class = MyResponse + client = app.test_client() + + res = client.get(url_for("ping"), headers=accept_json) + assert res.json == 42 From dcc32b6f0a6f19a18a9b900bc5e8f1c8ba413a9d Mon Sep 17 00:00:00 2001 From: northernSage Date: Thu, 11 Feb 2021 10:13:54 -0300 Subject: [PATCH 16/33] remove philosophical contemplation of existence --- tests/test_json_response.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_json_response.py b/tests/test_json_response.py index ecef59c..c144f66 100644 --- a/tests/test_json_response.py +++ b/tests/test_json_response.py @@ -24,7 +24,6 @@ def test_dont_rewrite_existing_implementation(self, app, accept_json): class MyResponse(app.response_class): @property def json(self): - """What is the meaning of life, the universe and everything?""" return 42 app.response_class = MyResponse From 2745316f7c2ea8b45f7a5579b65c5c4ff4b85336 Mon Sep 17 00:00:00 2001 From: northernSage Date: Thu, 11 Feb 2021 10:19:02 -0300 Subject: [PATCH 17/33] remove deprecation test --- tests/test_live_server.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_live_server.py b/tests/test_live_server.py index 7d5d6d5..85f1125 100755 --- a/tests/test_live_server.py +++ b/tests/test_live_server.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python import os from urllib.request import urlopen @@ -22,9 +21,6 @@ def test_server_url(self, live_server): assert live_server.url() == "http://localhost:%d" % live_server.port assert live_server.url("/ping") == "http://localhost:%d/ping" % live_server.port - def test_server_url_is_deprecated(self, live_server): - assert pytest.deprecated_call(live_server.url) - def test_server_listening(self, live_server): # need to test both external and external? why external here? # res = urlopen(url_for('ping', _external=True)) From fc79de0f003f211c5fcc49559b43520038321203 Mon Sep 17 00:00:00 2001 From: northernSage Date: Thu, 11 Feb 2021 10:33:20 -0300 Subject: [PATCH 18/33] remove test for deprecated method --- tests/test_live_server.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/test_live_server.py b/tests/test_live_server.py index 85f1125..f3f5a73 100755 --- a/tests/test_live_server.py +++ b/tests/test_live_server.py @@ -17,14 +17,8 @@ def test_server_is_alive(self, live_server): assert live_server._process assert live_server._process.is_alive() - def test_server_url(self, live_server): - assert live_server.url() == "http://localhost:%d" % live_server.port - assert live_server.url("/ping") == "http://localhost:%d/ping" % live_server.port - def test_server_listening(self, live_server): - # need to test both external and external? why external here? - # res = urlopen(url_for('ping', _external=True)) - res = urlopen(live_server.url("/ping")) + res = urlopen(url_for("ping", _external=True)) assert res.code == 200 assert b"pong" in res.read() From f20fc855b3c01100dda01d275ed931fa9922b5e3 Mon Sep 17 00:00:00 2001 From: northernSage Date: Thu, 11 Feb 2021 10:37:00 -0300 Subject: [PATCH 19/33] remove deprecated LiveServer.url --- pytest_flask/live_server.py | 13 ------------- tests/test_markers.py | 1 - 2 files changed, 14 deletions(-) diff --git a/pytest_flask/live_server.py b/pytest_flask/live_server.py index 9a8f8ee..23a0371 100644 --- a/pytest_flask/live_server.py +++ b/pytest_flask/live_server.py @@ -65,19 +65,6 @@ def _is_ready(self): sock.close() return ret - @deprecated( - reason=( - 'The "live_server.url" method is deprecated and will ' - "be removed in the future. Please use " - 'the "flask.url_for" function instead.', - ) - ) - def url(self, url=""): - """Returns the complete url based on server options.""" - return "http://{host!s}:{port!s}{url!s}".format( - host=self.host, port=self.port, url=url - ) - def stop(self): """Stop application process.""" if self._process: diff --git a/tests/test_markers.py b/tests/test_markers.py index 87dcc57..1186a1e 100755 --- a/tests/test_markers.py +++ b/tests/test_markers.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python import pytest from flask import Flask From ef07a17713d8e20bc35eee526200242430029413 Mon Sep 17 00:00:00 2001 From: Gabriel Fioravante Date: Tue, 16 Feb 2021 02:09:18 -0500 Subject: [PATCH 20/33] update coverage instructions to account for multiprocessing --- CONTRIBUTING.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index f31a115..170d1af 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -102,8 +102,8 @@ To get a complete report of code sections not being touched by the test suite run ``pytest`` using ``coverage``. .. code-block:: text - - $ coverage run -m pytest + $ coverage run --concurrency=multiprocessing -m pytest + $ coverage combine $ coverage html Open ``htmlcov/index.html`` in your browser. From 1fa0a02e656b22df38e50a718f0f63987566e248 Mon Sep 17 00:00:00 2001 From: northernSage Date: Tue, 16 Feb 2021 02:57:12 -0500 Subject: [PATCH 21/33] add .swp files to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index cd5362e..a8e2994 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ build sdist .vscode +*.swp __pycache__/ # virtualenv From b4d8b11c6a47422a74262962d3f30f2fd167936b Mon Sep 17 00:00:00 2001 From: northernSage Date: Tue, 16 Feb 2021 03:01:34 -0500 Subject: [PATCH 22/33] add new tests for fixtures and deprecation decorator --- tests/conftest.py | 1 + tests/test_fixtures.py | 8 ++++++++ tests/test_internal.py | 15 +++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 tests/test_internal.py diff --git a/tests/conftest.py b/tests/conftest.py index 595f386..bc2a66c 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,7 @@ from flask import Flask from flask import jsonify +from pytest_flask.fixtures import mimetype pytest_plugins = "pytester" diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 28ca31f..9691eff 100755 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -23,6 +23,14 @@ def test_request_ctx_is_kept_around(self, client): client.get(url_for("index"), headers=[("X-Something", "42")]) 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 + + def test_accept_any(self, accept_any): + mimestrings = [[("Accept", "*")], [("Accept", "*/*")]] + assert accept_any in mimestrings + @pytest.mark.usefixtures("client_class") class TestClientClass: diff --git a/tests/test_internal.py b/tests/test_internal.py new file mode 100644 index 0000000..603d39c --- /dev/null +++ b/tests/test_internal.py @@ -0,0 +1,15 @@ +import pytest + +from pytest_flask._internal import deprecated + + +class TestInternal: + def test_deprecation_decorator(self, appdir): + @deprecated(reason="testing decorator") + def deprecated_fun(): + pass + + with pytest.warns(DeprecationWarning) as record: + deprecated_fun() + assert len(record) == 1 + assert record[0].message.args[0] == "testing decorator" From 86e92b5d647c097208d4b0e49183d0c85a555a8f Mon Sep 17 00:00:00 2001 From: northernSage Date: Wed, 17 Feb 2021 02:54:17 -0300 Subject: [PATCH 23/33] add test for possible exception in liveserver._stop_cleanly() --- tests/test_live_server.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_live_server.py b/tests/test_live_server.py index f3f5a73..c0decab 100755 --- a/tests/test_live_server.py +++ b/tests/test_live_server.py @@ -76,6 +76,12 @@ def test_a(live_server): result.stdout.fnmatch_lines(["*passed*"]) assert result.ret == 0 + def test_stop_cleanly_join_exception(self, appdir, live_server, caplog): + # timeout = 'a' here to force an exception when + # attempting to self._process.join() + assert not live_server._stop_cleanly(timeout="a") + assert "Failed to join" in caplog.text + @pytest.mark.parametrize("clean_stop", [True, False]) def test_clean_stop_live_server(self, appdir, monkeypatch, clean_stop): """Ensure the fixture is trying to cleanly stop the server. From 21a3c1d29f1f1e7932736208027012ea1f592a95 Mon Sep 17 00:00:00 2001 From: northernSage Date: Wed, 17 Feb 2021 23:11:25 -0300 Subject: [PATCH 24/33] remove pytest-cov --- requirements/test.txt | 2 +- tox.ini | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/requirements/test.txt b/requirements/test.txt index c8834c6..d5339bb 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,4 +1,4 @@ mock pylint -pytest-cov +coverage pytest-pep8 diff --git a/tox.ini b/tox.ini index c911bc4..3a572f0 100644 --- a/tox.ini +++ b/tox.ini @@ -2,13 +2,11 @@ envlist = py{35,36,37,38,linting} - [pytest] norecursedirs = .git .tox env coverage docs pep8ignore = docs/conf.py ALL pep8maxlinelength = 119 -junit_family=xunit2 [testenv:dev] commands = @@ -31,19 +29,22 @@ deps = passenv = HOME LANG LC_ALL commands = - pytest --basetemp={envtmpdir} --confcutdir=tests \ - --junitxml=tests/junit.xml \ - --cov-report xml --cov pytest_flask \ - --cov-report=html \ - --cov-report term-missing \ - -ra \ - {posargs:tests} + coverage run -m pytest {posargs:tests} + coverage combine + coverage report [coverage:report] -omit = - */venv/* - */tmp/* - */tests/* +fail_under=90 + +[coverage:run] +source=pytest_flask +concurrency=multiprocessing + +[tool:pytest] +addopts = + -v + --basetemp={envtmpdir} + --confcutdir=tests [testenv:pre] pip_pre=true @@ -53,7 +54,7 @@ commands = {[testenv]commands} [testenv:linting] skip_install = True -basepython = python3 +basepython = python3.7 deps = pre-commit>=1.11.0 commands = pre-commit run --all-files --show-diff-on-failure {posargs:} From d9b5d5d3897e9f43aea9a9ee6238261dffff9cef Mon Sep 17 00:00:00 2001 From: northernSage Date: Fri, 19 Feb 2021 04:54:04 -0300 Subject: [PATCH 25/33] update for werkzeug 2.0.0 --- docs/changelog.rst | 5 +++-- pytest_flask/fixtures.py | 8 ++++++++ tests/test_fixtures.py | 12 ++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index da79cf6..5b59b76 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -3,11 +3,12 @@ Changelog ========= -1.1.1 (2020-11-08) +1.2.0 (2020-11-08) ------------------ - Remove deprecated ``:meth:live_server.url`` - +- fixture ``request_ctx is now deprecated`` use + ``:Attr:Werkzeug.test.TestResponse.request`` instead 1.1.0 (2020-11-08) ------------------ diff --git a/pytest_flask/fixtures.py b/pytest_flask/fixtures.py index 8563300..51c978e 100755 --- a/pytest_flask/fixtures.py +++ b/pytest_flask/fixtures.py @@ -7,6 +7,7 @@ from ._internal import _determine_scope from ._internal import _make_accept_header from ._internal import _rewrite_server_name +from ._internal import deprecated from .live_server import LiveServer @@ -91,6 +92,13 @@ def config(app): return app.config +@deprecated( + reason="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'" + "'request_ctx' will be removed in the future, using TestResponse.request is the" + "prefered way." +) @pytest.fixture def request_ctx(app): """The request context which contains all request relevant information, diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 9691eff..a55fd98 100755 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -20,8 +20,16 @@ def test_request_ctx(self, app, request_ctx): assert request_ctx.app is app def test_request_ctx_is_kept_around(self, client): - client.get(url_for("index"), headers=[("X-Something", "42")]) - assert request.headers["X-Something"] == "42" + 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 wich 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")]] From 2ad65079026091cf1a5e41155587ee05f36ae8d9 Mon Sep 17 00:00:00 2001 From: northernSage Date: Fri, 19 Feb 2021 05:05:06 -0300 Subject: [PATCH 26/33] fix deprecation warning --- pytest_flask/fixtures.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pytest_flask/fixtures.py b/pytest_flask/fixtures.py index 51c978e..eb25861 100755 --- a/pytest_flask/fixtures.py +++ b/pytest_flask/fixtures.py @@ -1,5 +1,6 @@ #!/usr/bin/env python import socket +import warnings import pytest from flask import _request_ctx_stack @@ -92,18 +93,20 @@ def config(app): return app.config -@deprecated( - reason="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'" - "'request_ctx' will be removed in the future, using TestResponse.request is the" - "prefered way." -) @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 prefered way.", + DeprecationWarning, + stacklevel=2, + ) return _request_ctx_stack.top From 4f69b91a940c02022cafcf45f9f53cc497c24f97 Mon Sep 17 00:00:00 2001 From: northernSage Date: Sat, 20 Feb 2021 06:36:35 -0300 Subject: [PATCH 27/33] remove old py2 code --- pytest_flask/plugin.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/pytest_flask/plugin.py b/pytest_flask/plugin.py index 1b9c8b6..24f6647 100755 --- a/pytest_flask/plugin.py +++ b/pytest_flask/plugin.py @@ -37,17 +37,7 @@ def json(self): def __eq__(self, other): if isinstance(other, int): return self.status_code == other - # even though the Python 2-specific code works on Python 3, keep the two versions - # separate so we can simplify the code once Python 2 support is dropped - if sys.version_info[0] == 2: - try: - super_eq = super().__eq__ - except AttributeError: - return NotImplemented - else: - return super_eq(other) - else: - return super().__eq__(other) + return super().__eq__(other) def __ne__(self, other): return not self == other From 602884a6a406ee3a5a0b48333d8ebbf2301092a3 Mon Sep 17 00:00:00 2001 From: northernSage Date: Sat, 20 Feb 2021 11:05:48 -0300 Subject: [PATCH 28/33] remove JSONResponse.json --- pytest_flask/plugin.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/pytest_flask/plugin.py b/pytest_flask/plugin.py index 24f6647..bb4bf59 100755 --- a/pytest_flask/plugin.py +++ b/pytest_flask/plugin.py @@ -26,14 +26,6 @@ class JSONResponse: """Mixin with testing helper methods for JSON responses.""" - @cached_property - def json(self): - """Try to deserialize response data (a string containing a valid JSON - document) to a Python object by passing it to the underlying - :mod:`flask.json` module. - """ - return json.loads(self.data) - def __eq__(self, other): if isinstance(other, int): return self.status_code == other @@ -81,6 +73,7 @@ def test_json(client): assert res.json == {'ping': 'pong'} """ + if "app" not in request.fixturenames: return From e58a893fde0bf4b95565449c57aa1ca75ce8a68f Mon Sep 17 00:00:00 2001 From: northernSage Date: Sun, 21 Feb 2021 02:24:22 -0300 Subject: [PATCH 29/33] adjust test for response overwriting --- tests/test_json_response.py | 13 +---------- tests/test_response_overwriting.py | 35 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 tests/test_response_overwriting.py diff --git a/tests/test_json_response.py b/tests/test_json_response.py index c144f66..370b1b7 100644 --- a/tests/test_json_response.py +++ b/tests/test_json_response.py @@ -1,4 +1,5 @@ import pytest +from flask import Flask from flask import url_for @@ -19,15 +20,3 @@ def test_mismatching_eq_comparison(self, client, accept_json): assert client.get("fake-route", headers=accept_json) == 200 with pytest.raises(AssertionError, match=r"404 NOT FOUND"): assert client.get("fake-route", headers=accept_json) == "200" - - def test_dont_rewrite_existing_implementation(self, app, accept_json): - class MyResponse(app.response_class): - @property - def json(self): - return 42 - - app.response_class = MyResponse - client = app.test_client() - - res = client.get(url_for("ping"), headers=accept_json) - assert res.json == 42 diff --git a/tests/test_response_overwriting.py b/tests/test_response_overwriting.py new file mode 100644 index 0000000..2e0dbb2 --- /dev/null +++ b/tests/test_response_overwriting.py @@ -0,0 +1,35 @@ +import pytest +from flask import Flask +from flask import jsonify +from flask import url_for + + +class TestResponseOverwriting: + """ + we overwrite the app fixture here so we can test + _monkeypatch_response_class (an autouse fixture) + will return the original response_class since a + json @property is already present in response_class + """ + + @pytest.fixture + def app(self): + app = Flask(__name__) + app.config["SECRET_KEY"] = "42" + + class MyResponse(app.response_class): + @property + def json(self): + return 49 + + @app.route("/ping") + def ping(): + return jsonify(ping="pong") + + app.response_class = MyResponse + + return app + + def test_dont_rewrite_existing_implementation(self, accept_json, client): + res = client.get(url_for("ping"), headers=accept_json) + assert res.json == 49 From e510985dcef32864ef8618040d95025e3db668f8 Mon Sep 17 00:00:00 2001 From: northernSage Date: Sun, 21 Feb 2021 02:25:15 -0300 Subject: [PATCH 30/33] skip coverage on old compat function --- pytest_flask/pytest_compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_flask/pytest_compat.py b/pytest_flask/pytest_compat.py index 315b4f1..1e2585c 100644 --- a/pytest_flask/pytest_compat.py +++ b/pytest_flask/pytest_compat.py @@ -2,4 +2,4 @@ def getfixturevalue(request, value): if hasattr(request, "getfixturevalue"): return request.getfixturevalue(value) - return request.getfuncargvalue(value) + return request.getfuncargvalue(value) # pragma: no cover From 1f31a40fc2248fdb03ed30e9038dc4ba5039de3b Mon Sep 17 00:00:00 2001 From: northernSage Date: Tue, 23 Feb 2021 05:38:42 -0300 Subject: [PATCH 31/33] update docs --- docs/features.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/features.rst b/docs/features.rst index cc2677c..2b00ca6 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -27,8 +27,8 @@ Extension provides some sugar for your tests, such as: .. note:: - User-defined ``json`` attribute/method in application response class does - not overrides. So you can define your own response deserialization method: + User-defined ``json`` attribute/method in application response class will + no be overwritten So you can define your own response deserialization method: .. code:: python @@ -83,9 +83,9 @@ An instance of ``app.test_client``. Typically refers to .. hint:: - During tests execution the request context has been pushed, e.g. - ``url_for``, ``session`` and other context bound objects are available - without context managers. + During test execution a request context will be automatically pushed + for you so context-bound methods can be conveniently called (e.g. + ``url_for``, ``session``. Example: @@ -145,7 +145,7 @@ other headless browsers). ``--no-start-live-server`` - don’t start live server automatically `````````````````````````````````````````````````````````````````` -By default the server is starting automatically whenever you reference +By default the server will start automatically whenever you reference ``live_server`` fixture in your tests. But starting live server imposes some high costs on tests that need it when they may not be ready yet. To prevent that behaviour pass ``--no-start-live-server`` into your default options (for @@ -188,9 +188,11 @@ in your project's ``pytest.ini`` file):: addopts = --live-server-port=5000 -``request_ctx`` - request context +``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:: @@ -228,7 +230,7 @@ Common request methods are available through the internals of the `Flask API`_. Specifically, the API creates the default `flask.Flask.test_client`_ instance, which works like a regular `Werkzeug test client`_. -Example: +Examples: .. code:: python @@ -247,8 +249,6 @@ Example: assert res.status_code == 200 -Example: - .. code:: python def test_get_request(client, live_server): From 7a428aaf5d8251c1c08b9200e9a30a51b4027172 Mon Sep 17 00:00:00 2001 From: northernSage Date: Tue, 23 Feb 2021 05:39:04 -0300 Subject: [PATCH 32/33] update changelog --- docs/changelog.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5b59b76..d82f640 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -3,12 +3,12 @@ Changelog ========= -1.2.0 (2020-11-08) +1.2.0 (UNRELEASED) ------------------ - Remove deprecated ``:meth:live_server.url`` -- fixture ``request_ctx is now deprecated`` use - ``:Attr:Werkzeug.test.TestResponse.request`` instead +- fixture ``request_ctx is now deprecated`` + and will be removed in the future 1.1.0 (2020-11-08) ------------------ From ef09718ac223f166fae9f325fde3d7733408d907 Mon Sep 17 00:00:00 2001 From: northernSage Date: Tue, 23 Feb 2021 05:41:49 -0300 Subject: [PATCH 33/33] fix doc typos --- docs/features.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/features.rst b/docs/features.rst index 2b00ca6..8253f54 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -28,7 +28,7 @@ Extension provides some sugar for your tests, such as: .. note:: User-defined ``json`` attribute/method in application response class will - no be overwritten So you can define your own response deserialization method: + not be overwritten. So you can define your own response deserialization method: .. code:: python @@ -84,7 +84,7 @@ An instance of ``app.test_client``. Typically refers to .. hint:: During test execution a request context will be automatically pushed - for you so context-bound methods can be conveniently called (e.g. + for you, so context-bound methods can be conveniently called (e.g. ``url_for``, ``session``. Example: @@ -145,7 +145,7 @@ other headless browsers). ``--no-start-live-server`` - don’t start live server automatically `````````````````````````````````````````````````````````````````` -By default the server will start automatically whenever you reference +By default the server will start automatically whenever you reference ``live_server`` fixture in your tests. But starting live server imposes some high costs on tests that need it when they may not be ready yet. To prevent that behaviour pass ``--no-start-live-server`` into your default options (for