Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/8940.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue where dirs without S_IXUSR prevented pytest from cleaning up the temp dir
9 changes: 3 additions & 6 deletions src/_pytest/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
from posixpath import sep as posix_sep
import shutil
import sys
import tempfile
import types
from types import ModuleType
from typing import Any
from typing import TypeVar
import uuid
import warnings

from _pytest.compat import assert_never
Expand Down Expand Up @@ -286,11 +286,8 @@ def maybe_delete_a_numbered_dir(path: Path) -> None:
lock_path = None
try:
lock_path = create_cleanup_lock(path)
parent = path.parent

garbage = parent.joinpath(f"garbage-{uuid.uuid4()}")
path.rename(garbage)
rm_rf(garbage)
with tempfile.TemporaryDirectory(prefix="garbage-", dir=path.parent) as garbage:
path.replace(garbage)
except OSError:
# known races:
# * other process did a cleanup at the same time
Expand Down
20 changes: 20 additions & 0 deletions testing/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,26 @@ def test_long_path_during_cleanup(tmp_path: Path) -> None:
assert not os.path.isdir(extended_path)


def test_permission_denied_during_cleanup(tmp_path: Path) -> None:
"""
Ensure that deleting a numbered dir does not fail because of missing file
permission bits (#7940).
"""
path = tmp_path / "temp-1"
p = path / "ham" / "spam" / "eggs"
p.parent.mkdir(parents=True)
p.touch(mode=0)
for parent in p.parents:
if parent == path:
break
parent.chmod(mode=0)

lock_path = get_lock_path(path)
maybe_delete_a_numbered_dir(path)
assert not path.exists()
assert not lock_path.is_file()


def test_get_extended_length_path_str() -> None:
assert get_extended_length_path_str(r"c:\foo") == r"\\?\c:\foo"
assert get_extended_length_path_str(r"\\share\foo") == r"\\?\UNC\share\foo"
Expand Down
Loading