Skip to content

Commit

Permalink
Skip permission tests as root (e.g. docker)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erotemic committed Sep 13, 2024
1 parent 88c0387 commit 136674e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions jsonargparse_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
reason="responses package is required",
)

skip_if_running_as_root = pytest.mark.skipif(
is_posix and os.geteuid() == 0,
reason="User is root, permission tests will not work",
)

if responses_available:
import responses

Expand Down
3 changes: 3 additions & 0 deletions jsonargparse_tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
skip_if_fsspec_unavailable,
skip_if_not_posix,
skip_if_responses_unavailable,
skip_if_running_as_root,
)


Expand Down Expand Up @@ -329,6 +330,7 @@ def test_parse_path_defaults(parser, tmp_cwd):


@skip_if_not_posix
@skip_if_running_as_root
def test_parse_path_file_not_readable(parser, tmp_cwd):
config_path = Path("config.json")
config_path.touch()
Expand Down Expand Up @@ -792,6 +794,7 @@ def test_default_config_file_invalid_value(parser, tmp_cwd):


@skip_if_not_posix
@skip_if_running_as_root
def test_default_config_file_unreadable(parser, tmp_cwd):
default_config_file = Path("defaults.yaml")
default_config_file.write_text("op1: from yaml\n")
Expand Down
4 changes: 4 additions & 0 deletions jsonargparse_tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
skip_if_fsspec_unavailable,
skip_if_requests_unavailable,
skip_if_responses_unavailable,
skip_if_running_as_root,
)

if responses_available:
Expand Down Expand Up @@ -136,6 +137,7 @@ def test_path_equality_operator(paths):
assert Path("123", "fc") != 123


@skip_if_running_as_root
def test_path_file_access_mode(paths):
Path(paths.file_rw, "frw")
Path(paths.file_r, "fr")
Expand All @@ -150,6 +152,7 @@ def test_path_file_access_mode(paths):
pytest.raises(TypeError, lambda: Path("file_ne", "fr"))


@skip_if_running_as_root
def test_path_dir_access_mode(paths):
Path(paths.dir_rwx, "drwx")
Path(paths.dir_rx, "drx")
Expand All @@ -166,6 +169,7 @@ def test_path_get_content(paths):
assert "file contents" == Path(f"file://{paths.tmp_path}/{paths.file_r}", "ur").get_content()


@skip_if_running_as_root
def test_path_create_mode(paths):
Path(paths.file_rw, "fcrw")
Path(paths.tmp_path / "file_c", "fc")
Expand Down

0 comments on commit 136674e

Please sign in to comment.