Skip to content

Commit 76890ef

Browse files
thorsten-kleinpdgendt
authored andcommitted
Extract test with non-readable config file
Creating a non-readable config file is not possible on Windows or when running as root. Since there is a west CI workflow executing tests as root, the test has failed. This change moves the test into a separate suite which is skipped on Windows or when running as root.
1 parent 58f0bdb commit 76890ef

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

tests/test_config.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,30 @@ def test_config_precedence():
703703
assert cfg(f=LOCAL)['pytest']['precedence'] == 'local'
704704

705705

706+
@pytest.mark.skipif(
707+
WINDOWS or (os.geteuid() == 0),
708+
reason="Non-readable files do not exist on Windows, and root user can always read files",
709+
)
710+
def test_config_non_readable_file(config_tmpdir):
711+
# test to read a config file without read permission
712+
cwd = pathlib.Path.cwd()
713+
714+
# create a readable file
715+
config_readable = cwd / 'readable'
716+
config_readable.touch()
717+
718+
# create a non-readable file
719+
config_non_readable = cwd / 'non-readable'
720+
config_non_readable.touch()
721+
config_non_readable.chmod(0o000)
722+
723+
# trying to use a non-readable config should result in according error
724+
with update_env({'WEST_CONFIG_GLOBAL': f'{config_readable}{os.pathsep}{config_non_readable}'}):
725+
_, stderr = cmd_raises('config --global some.section', MalformedConfig)
726+
expected = f"Error while reading one of '{[str(config_readable), str(config_non_readable)]}'"
727+
assert expected in stderr
728+
729+
706730
def test_config_multiple(config_tmpdir):
707731
# Verify that local settings take precedence over global ones,
708732
# but that both values are still available, and that setting
@@ -747,16 +771,6 @@ def run_and_assert(expected_values: dict[str, dict[str, str]]):
747771
write_config(config_l1, 'sec', 'l', '1', 'l1', '1')
748772
write_config(config_l2, 'sec', 'l', '2', 'l2', '2')
749773

750-
# config file without read permission (does not work on Windows)
751-
if not WINDOWS:
752-
config_non_readable = config_dir / 'non-readable'
753-
config_non_readable.touch()
754-
config_non_readable.chmod(0o000)
755-
with update_env({'WEST_CONFIG_GLOBAL': f'{config_g1}{os.pathsep}{config_non_readable}'}):
756-
_, stderr = cmd_raises('config --global some.section', MalformedConfig)
757-
expected = f"Error while reading one of '{[str(config_g1), str(config_non_readable)]}'"
758-
assert expected in stderr
759-
760774
# specify multiple configs for each config level (separated by os.pathsep)
761775
os.environ["WEST_CONFIG_GLOBAL"] = f'{config_g1}{os.pathsep}{config_g2}'
762776
os.environ["WEST_CONFIG_SYSTEM"] = f'{config_s1}{os.pathsep}{config_s2}'

0 commit comments

Comments
 (0)