File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 4545
4646@pytest .fixture
4747def 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
You can’t perform that action at this time.
0 commit comments