Skip to content

Commit 3bdab91

Browse files
rework existing tests to use new update_env() method
1 parent e0cefc8 commit 3bdab91

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

tests/test_config.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import Any
1010

1111
import pytest
12-
from conftest import cmd, cmd_raises
12+
from conftest import cmd, cmd_raises, update_env
1313

1414
from west import configuration as config
1515
from west.util import PathType
@@ -232,19 +232,18 @@ def test_local_creation_with_topdir():
232232
# The autouse fixture at the top of this file has set up an
233233
# environment variable for our local config file. Disable it
234234
# to make sure the API works with a 'real' topdir.
235-
del os.environ['WEST_CONFIG_LOCAL']
236-
237-
# We should be able to write into our topdir's config file now.
238-
update_testcfg('pytest', 'key', 'val', configfile=LOCAL, topdir=str(topdir))
239-
assert not system.exists()
240-
assert not glbl.exists()
241-
assert not local.exists()
242-
assert topdir_config.exists()
243-
244-
assert cfg(f=ALL, topdir=str(topdir))['pytest']['key'] == 'val'
245-
assert 'pytest' not in cfg(f=SYSTEM)
246-
assert 'pytest' not in cfg(f=GLOBAL)
247-
assert cfg(f=LOCAL, topdir=str(topdir))['pytest']['key'] == 'val'
235+
with update_env({'WEST_CONFIG_LOCAL': None}):
236+
# We should be able to write into our topdir's config file now.
237+
update_testcfg('pytest', 'key', 'val', configfile=LOCAL, topdir=str(topdir))
238+
assert not system.exists()
239+
assert not glbl.exists()
240+
assert not local.exists()
241+
assert topdir_config.exists()
242+
243+
assert cfg(f=ALL, topdir=str(topdir))['pytest']['key'] == 'val'
244+
assert 'pytest' not in cfg(f=SYSTEM)
245+
assert 'pytest' not in cfg(f=GLOBAL)
246+
assert cfg(f=LOCAL, topdir=str(topdir))['pytest']['key'] == 'val'
248247

249248

250249
def test_append():

tests/test_manifest.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
create_repo,
3232
create_workspace,
3333
rev_parse,
34+
update_env,
3435
)
3536

3637
from west.configuration import ConfigFile, Configuration, MalformedConfig
@@ -172,12 +173,9 @@ def test_manifest_from_file_with_fall_back(manifest_repo):
172173
''')
173174
repo_abspath = Path(str(manifest_repo))
174175
os.chdir(repo_abspath.parent.parent) # this is the tmp_workspace dir
175-
try:
176-
os.environ['ZEPHYR_BASE'] = os.fspath(manifest_repo)
176+
with update_env({'ZEPHYR_BASE': os.fspath(manifest_repo)}):
177177
manifest = MF()
178-
assert Path(manifest.repo_abspath) == repo_abspath
179-
finally:
180-
del os.environ['ZEPHYR_BASE']
178+
assert Path(manifest.repo_abspath) == repo_abspath
181179

182180

183181
def test_validate():

0 commit comments

Comments
 (0)