| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d966a0d commit 6fc4742
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -113,7 +113,7 @@ def test_deletes_dir_with_readonly_files(self, tmp_path): | |||
| 113 | 113 | sys.platform == "cygwin", | |
| 114 | 114 | reason="Cygwin can't set the permissions that make the test meaningful.", | |
| 115 | 115 | ) | |
| 116 | - def test_avoids_changing_permissions_outside_tree(self, tmp_path): | ||
| 116 | + def test_avoids_changing_permissions_outside_tree(self, tmp_path, request): | ||
| 117 | 117 | # Automatically works on Windows, but on Unix requires either special handling | |
| 118 | 118 | # or refraining from attempting to fix PermissionError by making chmod calls. | |
| 119 | 119 | ||
@@ -125,9 +125,32 @@ def test_avoids_changing_permissions_outside_tree(self, tmp_path): | |||
| 125 | 125 | ||
| 126 | 126 | dir2 = tmp_path / "dir2" | |
| 127 | 127 | dir2.mkdir() | |
| 128 | - (dir2 / "symlink").symlink_to(dir1 / "file") | ||
| 128 | + symlink = dir2 / "symlink" | ||
| 129 | + symlink.symlink_to(dir1 / "file") | ||
| 129 | 130 | dir2.chmod(stat.S_IRUSR | stat.S_IXUSR) | |
| 130 | 131 | ||
| 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 | + try: | ||
| 144 | + # Try lchmod first, if the platform supports it. | ||
| 145 | + symlink.lchmod(rwx) | ||
| 146 | + except NotImplementedError: | ||
| 147 | + # The platform (probably win32) doesn't support lchmod; fall back to chmod. | ||
| 148 | + symlink.chmod(rwx) | ||
| 149 | + dir2.chmod(rwx) | ||
| 150 | + rmtree(dir2) | ||
| 151 | + | ||
| 152 | + request.addfinalizer(preen_dir2) | ||
| 153 | + | ||
| 131 | 154 | try: | |
| 132 | 155 | rmtree(dir2) | |
| 133 | 156 | except PermissionError: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments