Skip to content

Commit 00c75c4

Browse files
authored
Merge pull request #12773 from matthewhughes934/fix-tests-unable-to-cleanup
2 parents 67e2a56 + 8cdf797 commit 00c75c4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

news/d475652f-fd8b-4be8-8057-411601597bee.trivial.rst

Whitespace-only changes.

tests/unit/test_utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ def test_rmtree_errorhandler_reraises_error(tmpdir: Path) -> None:
248248
by the given unreadable directory.
249249
"""
250250
# Create directory without read permission
251-
subdir_path = tmpdir / "subdir"
252-
subdir_path.mkdir()
253-
path = str(subdir_path)
254-
os.chmod(path, stat.S_IWRITE)
251+
path = tmpdir / "subdir"
252+
path.mkdir()
253+
old_mode = path.stat().st_mode
254+
path.chmod(stat.S_IWRITE)
255255

256256
mock_func = Mock()
257257

@@ -267,6 +267,9 @@ def test_rmtree_errorhandler_reraises_error(tmpdir: Path) -> None:
267267
rmtree_errorhandler(
268268
mock_func, path, sys.exc_info() # type: ignore[arg-type]
269269
)
270+
finally:
271+
# Restore permissions to let pytest to clean up temp dirs
272+
path.chmod(old_mode)
270273

271274
mock_func.assert_not_called()
272275

0 commit comments

Comments
 (0)