From 67c927c66da27aac69cffef9b470211df71845cc Mon Sep 17 00:00:00 2001 From: Cserna Zsolt Date: Tue, 13 Oct 2026 21:44:37 +0200 Subject: [PATCH] remove support for werkzeug < 2.3.0 --- doc/background.rst | 8 ++++---- pytest_httpserver/httpserver.py | 6 +----- .../notes/remove-werkzeug-compat-be170cf610b27025.yaml | 8 ++++++++ 3 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/remove-werkzeug-compat-be170cf610b27025.yaml diff --git a/doc/background.rst b/doc/background.rst index 2c4d035a..6d8f4fe5 100644 --- a/doc/background.rst +++ b/doc/background.rst @@ -124,10 +124,10 @@ library added to the requirements, which may cause compatibility issues. Requirements version restrictions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In general, the package requirements should have no version restrictions. For -example, the *werkzeug* library has no restrictions, which means that if a new -version comes out of it, it is assumed that *pytest-httpserver* will be able to -run with it. +In general, the package requirements should have as few version restrictions +as possible. The *werkzeug* library currently requires *werkzeug >= 3.0.0*, so +new versions of *werkzeug* are assumed to work with *pytest-httpserver*, +but older, unsupported versions are not. Many people uses this library in an environment having full of other packages and limiting version here will limit their versions in their requirements also. diff --git a/pytest_httpserver/httpserver.py b/pytest_httpserver/httpserver.py index 36913054..a1788ee0 100644 --- a/pytest_httpserver/httpserver.py +++ b/pytest_httpserver/httpserver.py @@ -26,7 +26,6 @@ from typing import ClassVar from typing import TypedDict -import werkzeug.http from werkzeug import Request from werkzeug import Response from werkzeug.datastructures import Authorization @@ -152,10 +151,7 @@ def __init__(self, matchers: Mapping[str, Callable[[str | None, str], bool]] | N @staticmethod def authorization_header_value_matcher(actual: str | None, expected: str) -> bool: - func = getattr(Authorization, "from_header", None) - if func is None: # Werkzeug < 2.3.0 - func = werkzeug.http.parse_authorization_header # type: ignore[attr-defined] - return func(actual) == func(expected) # type: ignore + return Authorization.from_header(actual) == Authorization.from_header(expected) @staticmethod def default_header_value_matcher(actual: str | None, expected: str) -> bool: diff --git a/releasenotes/notes/remove-werkzeug-compat-be170cf610b27025.yaml b/releasenotes/notes/remove-werkzeug-compat-be170cf610b27025.yaml new file mode 100644 index 00000000..20ea8553 --- /dev/null +++ b/releasenotes/notes/remove-werkzeug-compat-be170cf610b27025.yaml @@ -0,0 +1,8 @@ +--- +upgrade: + - | + Support for Werkzeug versions older than 3.0.0 has been removed as + pytest-httpserver now requires ``Werkzeug >= 3.0.0``. The fallback for + the deprecated ``werkzeug.http.parse_authorization_header`` has been + dropped from ``HeaderValueMatcher`` and the documentation has been + updated accordingly.