Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 335989f

Browse filesBrowse files
committed
test_avoids_changing...: don't leave test artifacts behind
Prior to this the test would fail [silently] on my macOS host during the test and then pytest would complain loudly about it being an issue post-session (regardless of whether or not the test was being run). Squash the unwritable directory to mute noise complaints from pytest. Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
1 parent d966a0d commit 335989f
Copy full SHA for 335989f

1 file changed

+20-2Lines changed: 20 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/test_util.py‎

Copy file name to clipboardExpand all lines: test/test_util.py
+20-2Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_deletes_dir_with_readonly_files(self, tmp_path):
113113
sys.platform == "cygwin",
114114
reason="Cygwin can't set the permissions that make the test meaningful.",
115115
)
116-
def test_avoids_changing_permissions_outside_tree(self, tmp_path):
116+
def test_avoids_changing_permissions_outside_tree(self, tmp_path, request):
117117
# Automatically works on Windows, but on Unix requires either special handling
118118
# or refraining from attempting to fix PermissionError by making chmod calls.
119119

@@ -125,9 +125,27 @@ def test_avoids_changing_permissions_outside_tree(self, tmp_path):
125125

126126
dir2 = tmp_path / "dir2"
127127
dir2.mkdir()
128-
(dir2 / "symlink").symlink_to(dir1 / "file")
128+
symlink = dir2 / "symlink"
129+
symlink.symlink_to(dir1 / "file")
129130
dir2.chmod(stat.S_IRUSR | stat.S_IXUSR)
130131

132+
def preen_dir2():
133+
"""Don't leave unwritable directories behind.
134+
135+
pytest has difficulties cleaning up after the fact on some platforms,
136+
e.g., macOS, and whines incessantly until the issue is resolved--regardless
137+
of the pytest session.
138+
"""
139+
rwx = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
140+
if not dir2.exists():
141+
return
142+
if symlink.exists():
143+
symlink.lchmod(rwx)
144+
dir2.chmod(rwx)
145+
rmtree(dir2)
146+
147+
request.addfinalizer(preen_dir2)
148+
131149
try:
132150
rmtree(dir2)
133151
except PermissionError:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.