Skip to content

Commit

Permalink
test: properly mock the environment (canonical#1385)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
tonyandrewmeyer authored Sep 22, 2024
1 parent 20c9623 commit 4bb92dd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit 4bb92dd

Please sign in to comment.