diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f832bdf..b9c5970 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: v5.0.0 + rev: v6.0.0 hooks: - id: check-byte-order-marker - id: trailing-whitespace @@ -9,16 +9,16 @@ repos: args: [--remove] - id: check-yaml - repo: https://github.com/asottile/reorder-python-imports - rev: v3.14.0 + rev: v3.16.0 hooks: - id: reorder-python-imports args: ['--application-directories=.:src', --py3-plus] -- repo: https://github.com/psf/black - rev: 24.10.0 +- repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.1.0 hooks: - id: black - repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 + rev: 7.3.0 hooks: - id: flake8 additional_dependencies: [flake8-bugbear] @@ -35,7 +35,7 @@ repos: hooks: - id: autoflake - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.14.1 + rev: v1.19.1 hooks: - id: mypy files: ^(src/|tests/) diff --git a/src/pytest_flask/_internal.py b/src/pytest_flask/_internal.py index df52314..ec5c9d4 100644 --- a/src/pytest_flask/_internal.py +++ b/src/pytest_flask/_internal.py @@ -5,7 +5,6 @@ from pytest import Config as _PytestConfig - _PytestScopeName = Literal["session", "package", "module", "class", "function"] diff --git a/src/pytest_flask/plugin.py b/src/pytest_flask/plugin.py index 6bb78d5..cf4641e 100644 --- a/src/pytest_flask/plugin.py +++ b/src/pytest_flask/plugin.py @@ -1,10 +1,11 @@ #!/usr/bin/env python """ - A py.test plugin which helps testing Flask applications. +A py.test plugin which helps testing Flask applications. - :copyright: (c) by Vital Kudzelka - :license: MIT +:copyright: (c) by Vital Kudzelka +:license: MIT """ + from typing import Any from typing import List from typing import Protocol @@ -25,7 +26,6 @@ from .fixtures import live_server from .pytest_compat import getfixturevalue - _Response = TypeVar("_Response") diff --git a/tests/test_live_server.py b/tests/test_live_server.py index 3f365aa..3cedd0b 100755 --- a/tests/test_live_server.py +++ b/tests/test_live_server.py @@ -3,7 +3,6 @@ import pytest from flask import url_for - pytestmark = pytest.mark.skipif(not hasattr(os, "fork"), reason="needs fork") @@ -35,44 +34,38 @@ def test_set_application_server_name(self, live_server): ) def test_rewrite_application_server_name(self, appdir): - appdir.create_test_module( - """ + appdir.create_test_module(""" import pytest @pytest.mark.options(server_name='example.com:5000') def test_a(live_server): assert live_server.app.config['SERVER_NAME'] == \\ 'example.com:%d' % live_server.port - """ - ) + """) result = appdir.runpytest("-v", "-o", "live_server_scope=function") result.stdout.fnmatch_lines(["*PASSED*"]) assert result.ret == 0 def test_prevent_starting_live_server(self, appdir): - appdir.create_test_module( - """ + appdir.create_test_module(""" import pytest def test_a(live_server): assert live_server._process is None - """ - ) + """) result = appdir.runpytest("-v", "--no-start-live-server") result.stdout.fnmatch_lines(["*passed*"]) assert result.ret == 0 def test_start_live_server(self, appdir): - appdir.create_test_module( - """ + appdir.create_test_module(""" import pytest def test_a(live_server): assert live_server._process assert live_server._process.is_alive() - """ - ) + """) result = appdir.runpytest("-v", "--start-live-server") result.stdout.fnmatch_lines(["*passed*"]) assert result.ret == 0 @@ -103,8 +96,7 @@ def mocked_stop_cleanly(*args, **kwargs): monkeypatch.setattr(LiveServer, "_stop_cleanly", mocked_stop_cleanly) - appdir.create_test_module( - """ + appdir.create_test_module(""" import pytest from flask import url_for @@ -119,8 +111,7 @@ def index(): res = client.get(url_for('index', _external=True)) assert res.status_code == 200 assert b'got it' in res.data - """ - ) + """) args = [] if clean_stop else ["--no-live-server-clean-stop"] result = appdir.runpytest_inprocess("-v", "--no-start-live-server", *args) result.stdout.fnmatch_lines("*1 passed*") @@ -130,8 +121,7 @@ def index(): assert stop_cleanly_result == [] def test_add_endpoint_to_live_server(self, appdir): - appdir.create_test_module( - """ + appdir.create_test_module(""" import pytest from flask import url_for @@ -146,16 +136,14 @@ def new_endpoint(): res = client.get(url_for('new_endpoint', _external=True)) assert res.status_code == 200 assert b'got it' in res.data - """ - ) + """) result = appdir.runpytest("-v", "--no-start-live-server") result.stdout.fnmatch_lines(["*passed*"]) assert result.ret == 0 @pytest.mark.skip("this test hangs in the original code") def test_concurrent_requests_to_live_server(self, appdir): - appdir.create_test_module( - """ + appdir.create_test_module(""" import pytest from flask import url_for @@ -175,51 +163,42 @@ def two(): res = client.get(url_for('one', _external=True)) assert res.status_code == 200 assert b'42' in res.data - """ - ) + """) result = appdir.runpytest("-v", "--no-start-live-server") result.stdout.fnmatch_lines(["*passed*"]) assert result.ret == 0 @pytest.mark.parametrize("port", [5000, 5001]) def test_live_server_fixed_port(self, port, appdir): - appdir.create_test_module( - """ + appdir.create_test_module(""" import pytest def test_port(live_server): assert live_server.port == %d - """ - % port - ) + """ % port) result = appdir.runpytest("-v", "--live-server-port", str(port)) result.stdout.fnmatch_lines(["*PASSED*"]) assert result.ret == 0 @pytest.mark.parametrize("host", ["127.0.0.1", "0.0.0.0"]) def test_live_server_fixed_host(self, host, appdir): - appdir.create_test_module( - """ + appdir.create_test_module(""" import pytest def test_port(live_server): assert live_server.host == '%s' - """ - % host - ) + """ % host) result = appdir.runpytest("-v", "--live-server-host", str(host)) result.stdout.fnmatch_lines(["*PASSED*"]) assert result.ret == 0 def test_respect_wait_timeout(self, appdir): - appdir.create_test_module( - """ + appdir.create_test_module(""" import pytest def test_should_fail(live_server): assert live_server._process.is_alive() - """ - ) + """) result = appdir.runpytest("-v", "--live-server-wait=0.00000001") result.stdout.fnmatch_lines(["**ERROR**"]) assert result.ret == 1