Skip to content

Commit

Permalink
fix pytest-dev#4135 - handle symlinks in tmp path cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Oct 14, 2018
1 parent 0be84cd commit 1dfa303
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/4135.bugfix.rst
@@ -0,0 +1 @@
pathlib based tmpdir cleanup now correctly handles symlinks in the folder.
2 changes: 2 additions & 0 deletions src/_pytest/pathlib.py
Expand Up @@ -173,6 +173,8 @@ def delete_a_numbered_dir(path):

def ensure_deletable(path, consider_lock_dead_if_created_before):
"""checks if a lock exists and breaks it if its considered dead"""
if path.is_symlink():
return False
lock = get_lock_path(path)
if not lock.exists():
return True
Expand Down
10 changes: 9 additions & 1 deletion testing/test_tmpdir.py
Expand Up @@ -232,7 +232,7 @@ def test_lock_register_cleanup_removal(self, tmp_path):

assert not lock.exists()

def test_cleanup_keep(self, tmp_path):
def _do_cleanup(self, tmp_path):
self.test_make(tmp_path)
from _pytest.pathlib import cleanup_numbered_dir

Expand All @@ -242,6 +242,9 @@ def test_cleanup_keep(self, tmp_path):
keep=2,
consider_lock_dead_if_created_before=0,
)

def test_cleanup_keep(self, tmp_path):
self._do_cleanup(tmp_path)
a, b = tmp_path.iterdir()
print(a, b)

Expand Down Expand Up @@ -275,3 +278,8 @@ def test_rmtree(self, tmp_path):

rmtree(adir, force=True)
assert not adir.exists()

def test_cleanup_symlink(self, tmp_path):
the_symlink = tmp_path / (self.PREFIX + "current")
the_symlink.symlink_to(tmp_path / (self.PREFIX + "5"))
self._do_cleanup(tmp_path)

0 comments on commit 1dfa303

Please sign in to comment.