Skip to content

Commit

Permalink
Improve the test and fix maybe_delete_a_numbered_dir for long paths
Browse files Browse the repository at this point in the history
Related to #6755
  • Loading branch information
nicoddemus committed May 30, 2020
1 parent f7ad71d commit 163d36e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/_pytest/pathlib.py
Expand Up @@ -251,6 +251,7 @@ def cleanup_on_exit(lock_path: Path = lock_path, original_pid: int = pid) -> Non

def maybe_delete_a_numbered_dir(path: Path) -> None:
"""removes a numbered directory if its lock can be obtained and it does not seem to be in use"""
path = ensure_extended_length_path(path)
lock_path = None
try:
lock_path = create_cleanup_lock(path)
Expand Down
13 changes: 7 additions & 6 deletions testing/test_pathlib.py
Expand Up @@ -94,17 +94,18 @@ def renamed_failed(*args):

def test_long_path_during_cleanup(tmp_path):
"""Ensure that deleting long path works (particularly on Windows (#6775))."""
path = tmp_path / ("a" * 250)
path = (tmp_path / ("a" * 250)).resolve()
if sys.platform == "win32":
dirname = path.resolve()
# make sure that the full path is > 260 characters without any
# component being over 260 characters
assert len(str(path)) > 260
dirname = "\\\\?\\" + str(path)
os.mkdir(dirname)
lock_path = get_lock_path(path)
extended_path = "\\\\?\\" + str(path)
else:
extended_path = str(path)
os.mkdir(extended_path)
assert os.path.isdir(extended_path)
maybe_delete_a_numbered_dir(path)

This comment has been minimized.

Copy link
@nicoddemus

nicoddemus May 30, 2020

Author Member

This ensures that maybe_delete_a_numbered_dir can delete a non-extended long path.

This comment has been minimized.

Copy link
@RonnyPfannschmidt

RonnyPfannschmidt May 30, 2020

Member

@nicoddemus i wonder if something like this could sort some of the setuptools_scm issues on windows wrtlong paths

This comment has been minimized.

Copy link
@nicoddemus

nicoddemus May 30, 2020

Author Member

Probably yes, it is part of the official Windows API.

assert not lock_path.is_file()
assert not os.path.isdir(extended_path)


def test_get_extended_length_path_str():
Expand Down

0 comments on commit 163d36e

Please sign in to comment.