Skip to content

Commit b9f485f

Browse files
author
Spece
committed
#2079 Satisfy.
1 parent 271328f commit b9f485f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

test/test_util.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@
4545

4646
@pytest.fixture
4747
def permission_error_tmpdir(tmp_path):
48-
"""Fixture to test permissions errors in situations where they are not overcome."""
48+
"""Fixture to test permissions errors when they cannot be bypassed.
49+
50+
On Unix-like systems the setup relies on running as a non-root user so that
51+
removing a read-only directory raises ``PermissionError``. When the tests
52+
execute with root privileges the expected error will not occur, so we skip
53+
them explicitly to avoid false failures.
54+
"""
4955
td = tmp_path / "testdir"
5056
td.mkdir()
5157
(td / "x").touch()
@@ -54,10 +60,13 @@ def permission_error_tmpdir(tmp_path):
5460
(td / "x").chmod(stat.S_IRUSR)
5561

5662
# Set up PermissionError on Unix, where non-root users can't delete files in
57-
# read-only directories. (Tests that rely on this and assert that rmtree raises
58-
# PermissionError will fail if they are run as root.)
63+
# read-only directories. Skip when running as root because the permission
64+
# change would not trigger the expected failure.
5965
td.chmod(stat.S_IRUSR | stat.S_IXUSR)
6066

67+
if hasattr(os, "geteuid") and os.geteuid() == 0:
68+
pytest.skip("permission_error_tmpdir requires non-root privileges to raise PermissionError")
69+
6170
yield td
6271

6372

0 commit comments

Comments
 (0)