Skip to content

Commit 33aef22

Browse files
Tor ColvinTor Colvin
authored andcommitted
long path fixes
1 parent d18c75b commit 33aef22

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/_pytest/pathlib.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,18 @@ def chmod_rw(p: str) -> None:
9999
func(path)
100100
return True
101101

102+
def create_long_path(path: Path) -> Path:
103+
if sys.platform.startswith("win32"):
104+
path = path.resolve()
105+
if not str(path).startswith(r"\\?"):
106+
path = Path(r"\\?" + str(path))
107+
return path
102108

103109
def rm_rf(path: Path) -> None:
104110
"""Remove the path contents recursively, even if some elements
105111
are read-only.
106112
"""
113+
path = create_long_path(path)
107114
onerror = partial(on_rm_rf_error, start_path=path)
108115
shutil.rmtree(str(path), onerror=onerror)
109116

testing/test_pathlib.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,15 @@ def renamed_failed(*args):
8989
lock_path = get_lock_path(path)
9090
maybe_delete_a_numbered_dir(path)
9191
assert not lock_path.is_file()
92+
93+
def test_long_path_during_cleanup(tmp_path):
94+
"""Ensure that deleting long path will be able to be deleted"""
95+
path = tmp_path / ("a" * 200)
96+
if sys.platform == "win32":
97+
dirname = path.resolve()
98+
dirname = "\\\\?\\" + str(path)
99+
os.mkdir(dirname)
100+
101+
lock_path = get_lock_path(path)
102+
maybe_delete_a_numbered_dir(path)
103+
assert not lock_path.is_file()

0 commit comments

Comments
 (0)