Skip to content

Commit 99c1f84

Browse files
rework existing tests to use new update_env() method
1 parent 2e32aa7 commit 99c1f84

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
@@ -213,19 +213,18 @@ def test_local_creation_with_topdir():
213213
# The autouse fixture at the top of this file has set up an
214214
# environment variable for our local config file. Disable it
215215
# to make sure the API works with a 'real' topdir.
216-
del os.environ['WEST_CONFIG_LOCAL']
217-
218-
# We should be able to write into our topdir's config file now.
219-
update_testcfg('pytest', 'key', 'val', configfile=LOCAL, topdir=str(topdir))
220-
assert not system.exists()
221-
assert not glbl.exists()
222-
assert not local.exists()
223-
assert topdir_config.exists()
224-
225-
assert cfg(f=ALL, topdir=str(topdir))['pytest']['key'] == 'val'
226-
assert 'pytest' not in cfg(f=SYSTEM)
227-
assert 'pytest' not in cfg(f=GLOBAL)
228-
assert cfg(f=LOCAL, topdir=str(topdir))['pytest']['key'] == 'val'
216+
with update_env({'WEST_CONFIG_LOCAL': None}):
217+
# We should be able to write into our topdir's config file now.
218+
update_testcfg('pytest', 'key', 'val', configfile=LOCAL, topdir=str(topdir))
219+
assert not system.exists()
220+
assert not glbl.exists()
221+
assert not local.exists()
222+
assert topdir_config.exists()
223+
224+
assert cfg(f=ALL, topdir=str(topdir))['pytest']['key'] == 'val'
225+
assert 'pytest' not in cfg(f=SYSTEM)
226+
assert 'pytest' not in cfg(f=GLOBAL)
227+
assert cfg(f=LOCAL, topdir=str(topdir))['pytest']['key'] == 'val'
229228

230229
def test_append():
231230
update_testcfg('pytest', 'key', 'system', configfile=SYSTEM)

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
@@ -164,12 +165,9 @@ def test_manifest_from_file_with_fall_back(manifest_repo):
164165
''')
165166
repo_abspath = Path(str(manifest_repo))
166167
os.chdir(repo_abspath.parent.parent) # this is the tmp_workspace dir
167-
try:
168-
os.environ['ZEPHYR_BASE'] = os.fspath(manifest_repo)
168+
with update_env({'ZEPHYR_BASE': os.fspath(manifest_repo)}):
169169
manifest = MF()
170-
assert Path(manifest.repo_abspath) == repo_abspath
171-
finally:
172-
del os.environ['ZEPHYR_BASE']
170+
assert Path(manifest.repo_abspath) == repo_abspath
173171

174172
def test_validate():
175173
# Get some coverage for west.manifest.validate.

0 commit comments

Comments
 (0)