diff --git a/news/d475652f-fd8b-4be8-8057-411601597bee.trivial.rst b/news/d475652f-fd8b-4be8-8057-411601597bee.trivial.rst new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 102b0340a14..aa9e7fd56c2 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -248,10 +248,10 @@ def test_rmtree_errorhandler_reraises_error(tmpdir: Path) -> None: by the given unreadable directory. """ # Create directory without read permission - subdir_path = tmpdir / "subdir" - subdir_path.mkdir() - path = str(subdir_path) - os.chmod(path, stat.S_IWRITE) + path = tmpdir / "subdir" + path.mkdir() + old_mode = path.stat().st_mode + path.chmod(stat.S_IWRITE) mock_func = Mock() @@ -267,6 +267,9 @@ def test_rmtree_errorhandler_reraises_error(tmpdir: Path) -> None: rmtree_errorhandler( mock_func, path, sys.exc_info() # type: ignore[arg-type] ) + finally: + # Restore permissions to let pytest to clean up temp dirs + path.chmod(old_mode) mock_func.assert_not_called()