Don't use pytest-mock mocker.patch as context manager

Quote from `pytest-mock` docs [1]:

> The purpose of this plugin is to make the use of context managers and
> function decorators for mocking unnecessary, so it will emit a warning
> when used as such.

Thus using it as a context manager currently produces a warning during
test runs in CI which is extra noise that could make new (possibly more
important) warnings harder to spot.

[1]: https://pytest-mock.readthedocs.io/en/latest/usage.html#usage-as-context-manager
This commit is contained in:
Naglis Jonaitis 2024-04-19 20:35:48 +03:00 committed by Alex Pyrgiotis
parent c3a570eb7d
commit 5b6cc861d8
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA

View file

@ -74,12 +74,13 @@ def test_new_default_setting(tmp_path: Path, mocker: MockerFixture) -> None:
settings.save() settings.save()
# Ensure new default setting is imported into settings # Ensure new default setting is imported into settings
with mocker.patch( mocker.patch(
"dangerzone.settings.Settings.generate_default_settings", "dangerzone.settings.Settings.generate_default_settings",
return_value={"mock_setting": 1}, return_value={"mock_setting": 1},
): )
settings2 = Settings(dz_core)
assert settings2.get("mock_setting") == 1 settings2 = Settings(dz_core)
assert settings2.get("mock_setting") == 1
def test_new_settings_added(tmp_path: Path, mocker: MockerFixture) -> None: def test_new_settings_added(tmp_path: Path, mocker: MockerFixture) -> None: