From 4bb92dd898bfd0ebaac4ba5890d007fb4d279776 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 23 Sep 2024 11:10:26 +1200 Subject: [PATCH] test: properly mock the environment (#1385) These two tests change `os.environ` without restoring it afterwards, which means that the changes leak into other tests. Change that by using `monkeypatch.setenv`. --- test/test_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_model.py b/test/test_model.py index 7af32262d..1f0b6391c 100644 --- a/test/test_model.py +++ b/test/test_model.py @@ -3246,7 +3246,7 @@ def test_relation_remote_app_name_env(self, monkeypatch: pytest.MonkeyPatch): monkeypatch.setenv('JUJU_RELATION_ID', 'x:5') monkeypatch.setenv('JUJU_REMOTE_APP', 'remoteapp1') assert self.backend.relation_remote_app_name(5) == 'remoteapp1' - os.environ['JUJU_RELATION_ID'] = '5' + monkeypatch.setenv('JUJU_RELATION_ID', '5') assert self.backend.relation_remote_app_name(5) == 'remoteapp1' def test_relation_remote_app_name_script_success( @@ -3270,7 +3270,7 @@ def test_relation_remote_app_name_script_success( # JUJU_RELATION_ID unset but JUJU_REMOTE_APP set monkeypatch.delenv('JUJU_RELATION_ID') - os.environ['JUJU_REMOTE_APP'] = 'remoteapp1' + monkeypatch.setenv('JUJU_REMOTE_APP', 'remoteapp1') assert self.backend.relation_remote_app_name(5) == 'remoteapp2' # Both set, but JUJU_RELATION_ID a different relation