From ccdea5dd028e2c4401aa8991aef12246e3a6a38b Mon Sep 17 00:00:00 2001 From: BarnabasG Date: Thu, 13 Nov 2025 21:05:54 +0000 Subject: [PATCH] 1.2.2 Fixing flask testclient.open logic --- pyproject.toml | 2 +- src/pytest_api_cov/plugin.py | 11 ++++++++--- uv.lock | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e9fc9cf..fb16456 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pytest-api-cov" -version = "1.2.1" +version = "1.2.2" description = "Pytest Plugin to provide API Coverage statistics for Python Web Frameworks" readme = "README.md" authors = [{ name = "Barnaby Gill", email = "barnabasgill@gmail.com" }] diff --git a/src/pytest_api_cov/plugin.py b/src/pytest_api_cov/plugin.py index 330e987..da62576 100644 --- a/src/pytest_api_cov/plugin.py +++ b/src/pytest_api_cov/plugin.py @@ -246,7 +246,10 @@ def _extract_path_and_method(self, name: str, args: Any, kwargs: Any) -> Optiona first = args[0] if isinstance(first, str): path = first.partition("?")[0] - method = name.upper() + method = kwargs.get("method", name).upper() + if method == "OPEN": + method = "GET" + return path, method # For starlette/requests TestClient, args[0] may be a Request or PreparedRequest @@ -259,19 +262,21 @@ def _extract_path_and_method(self, name: str, args: Any, kwargs: Any) -> Optiona else: return path, method - # Try kwargs-based FlaskClient open signature if kwargs: path_kw = kwargs.get("path") or kwargs.get("url") or kwargs.get("uri") if isinstance(path_kw, str): path = path_kw.partition("?")[0] method = kwargs.get("method", name).upper() + if method == "OPEN": + method = "GET" + return path, method return None def __getattr__(self, name: str) -> Any: attr = getattr(self._wrapped, name) - if name in ["get", "post", "put", "delete", "patch", "head", "options"]: + if name in {"get", "post", "put", "delete", "patch", "head", "options"}: def tracked_method(*args: Any, **kwargs: Any) -> Any: response = attr(*args, **kwargs) diff --git a/uv.lock b/uv.lock index 3035dfa..7254317 100644 --- a/uv.lock +++ b/uv.lock @@ -661,7 +661,7 @@ wheels = [ [[package]] name = "pytest-api-cov" -version = "1.2.1" +version = "1.2.2" source = { editable = "." } dependencies = [ { name = "fastapi" },