From 33b13efa7d472d1ff095bfc705d6bade34194f70 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Feb 2024 20:50:11 +0000 Subject: [PATCH 1/3] Bump pytest from 7.4.4 to 8.0.0 Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.4.4 to 8.0.0. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.4.4...8.0.0) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- poetry.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/poetry.lock b/poetry.lock index f12ba8fb8a..f9aadfbb99 100644 --- a/poetry.lock +++ b/poetry.lock @@ -3209,13 +3209,13 @@ files = [ [[package]] name = "pytest" -version = "7.4.4" +version = "8.0.0" description = "pytest: simple powerful testing with Python" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "pytest-7.4.4-py3-none-any.whl", hash = "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8"}, - {file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"}, + {file = "pytest-8.0.0-py3-none-any.whl", hash = "sha256:50fb9cbe836c3f20f0dfa99c565201fb75dc54c8d76373cd1bde06b06657bdb6"}, + {file = "pytest-8.0.0.tar.gz", hash = "sha256:249b1b0864530ba251b7438274c4d251c58d868edaaec8762893ad4a0d71c36c"}, ] [package.dependencies] @@ -3223,7 +3223,7 @@ colorama = {version = "*", markers = "sys_platform == \"win32\""} exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} iniconfig = "*" packaging = "*" -pluggy = ">=0.12,<2.0" +pluggy = ">=1.3.0,<2.0" tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} [package.extras] From 25c3a0e160828f42bcc99c31c61865cb9d04a50d Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Thu, 8 Feb 2024 20:16:37 -0400 Subject: [PATCH 2/3] See if this fixes things --- tests/api/admin/test_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api/admin/test_config.py b/tests/api/admin/test_config.py index 3338c62133..1c30bde323 100644 --- a/tests/api/admin/test_config.py +++ b/tests/api/admin/test_config.py @@ -17,7 +17,7 @@ def _set_env(monkeypatch, key: str, value: str | None): elif key in os.environ: monkeypatch.delenv(key) - def test_package_version_cached(self, monkeypatch): + def test_package_version_cached(self): with patch( "api.admin.config.Configuration.env_package_version" ) as env_package_version: From d9549b94d2c8896bab5949f49deadb5ea16e47b1 Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Fri, 9 Feb 2024 09:41:22 -0400 Subject: [PATCH 3/3] Fix test --- tests/api/admin/test_config.py | 59 +++++++++++++++++----------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/tests/api/admin/test_config.py b/tests/api/admin/test_config.py index 1c30bde323..2517710a13 100644 --- a/tests/api/admin/test_config.py +++ b/tests/api/admin/test_config.py @@ -3,24 +3,33 @@ from unittest.mock import MagicMock, patch import pytest +from _pytest.monkeypatch import MonkeyPatch from requests import RequestException from api.admin.config import Configuration as AdminConfig from api.admin.config import OperationalMode -class TestAdminUI: - @staticmethod - def _set_env(monkeypatch, key: str, value: str | None): +class MonkeyPatchEnvFixture: + def __init__(self, monkeypatch: MonkeyPatch): + self.monkeypatch = monkeypatch + + def __call__(self, key: str, value: str | None) -> None: if value: - monkeypatch.setenv(key, value) + self.monkeypatch.setenv(key, value) elif key in os.environ: - monkeypatch.delenv(key) + self.monkeypatch.delenv(key) + + +@pytest.fixture +def monkeypatch_env(monkeypatch: MonkeyPatch) -> MonkeyPatchEnvFixture: + return MonkeyPatchEnvFixture(monkeypatch) + +class TestAdminUI: def test_package_version_cached(self): - with patch( - "api.admin.config.Configuration.env_package_version" - ) as env_package_version: + with patch.object(AdminConfig, "env_package_version") as env_package_version: + AdminConfig._version = None env_package_version.return_value = None # The first call to package_version() should call env_package_version() @@ -45,18 +54,16 @@ def test_package_version_cached(self): ) def test_env_package_version( self, - monkeypatch, + monkeypatch_env: MonkeyPatchEnvFixture, package_version: str | None, resolves: bool, expected_result: str | None, ): - with patch( - "api.admin.config.Configuration.resolve_package_version" + with patch.object( + AdminConfig, "resolve_package_version" ) as resolve_package_version: resolve_package_version.return_value = "x.x.x" - self._set_env( - monkeypatch, "TPP_CIRCULATION_ADMIN_PACKAGE_VERSION", package_version - ) + monkeypatch_env("TPP_CIRCULATION_ADMIN_PACKAGE_VERSION", package_version) assert AdminConfig.env_package_version() == expected_result assert resolve_package_version.call_count == (1 if resolves else 0) @@ -110,16 +117,14 @@ def test_resolve_package_version(self, caplog): ) def test_package_url( self, - monkeypatch, + monkeypatch_env: MonkeyPatchEnvFixture, package_name: str | None, package_version: str | None, mode: OperationalMode, expected_result_startswith: str, ): - self._set_env(monkeypatch, "TPP_CIRCULATION_ADMIN_PACKAGE_NAME", package_name) - self._set_env( - monkeypatch, "TPP_CIRCULATION_ADMIN_PACKAGE_VERSION", package_version - ) + monkeypatch_env("TPP_CIRCULATION_ADMIN_PACKAGE_NAME", package_name) + monkeypatch_env("TPP_CIRCULATION_ADMIN_PACKAGE_VERSION", package_version) result = AdminConfig.package_url(_operational_mode=mode) assert result.startswith(expected_result_startswith) # Reset the cached version @@ -143,15 +148,13 @@ def test_package_url( ) def test_package_development_directory( self, - monkeypatch, + monkeypatch_env: MonkeyPatchEnvFixture, package_name: str | None, package_version: str | None, expected_result: str, ): - self._set_env(monkeypatch, "TPP_CIRCULATION_ADMIN_PACKAGE_NAME", package_name) - self._set_env( - monkeypatch, "TPP_CIRCULATION_ADMIN_PACKAGE_VERSION", package_version - ) + monkeypatch_env("TPP_CIRCULATION_ADMIN_PACKAGE_NAME", package_name) + monkeypatch_env("TPP_CIRCULATION_ADMIN_PACKAGE_VERSION", package_version) result = AdminConfig.package_development_directory(_base_dir="/my-base-dir") assert result == expected_result @@ -192,15 +195,13 @@ def test_package_development_directory( ) def test_lookup_asset_url( self, - monkeypatch, + monkeypatch_env: MonkeyPatchEnvFixture, asset_key: str, operational_mode: OperationalMode, expected_result: str, ): - self._set_env( - monkeypatch, "TPP_CIRCULATION_ADMIN_PACKAGE_NAME", "known-package-name" - ) - self._set_env(monkeypatch, "TPP_CIRCULATION_ADMIN_PACKAGE_VERSION", "1.0.0") + monkeypatch_env("TPP_CIRCULATION_ADMIN_PACKAGE_NAME", "known-package-name") + monkeypatch_env("TPP_CIRCULATION_ADMIN_PACKAGE_VERSION", "1.0.0") result = AdminConfig.lookup_asset_url( key=asset_key, _operational_mode=operational_mode )