File tree Expand file tree Collapse file tree 3 files changed +26
-7
lines changed
Expand file tree Collapse file tree 3 files changed +26
-7
lines changed Original file line number Diff line number Diff line change 1+ Fixed an issue where dirs without S_IXUSR prevented pytest from cleaning up the temp dir
Original file line number Diff line number Diff line change 66import os
77import shutil
88import sys
9- import uuid
9+ import tempfile
1010import warnings
1111from enum import Enum
1212from functools import partial
@@ -254,11 +254,10 @@ def maybe_delete_a_numbered_dir(path: Path) -> None:
254254 lock_path = None
255255 try :
256256 lock_path = create_cleanup_lock (path )
257- parent = path .parent
258-
259- garbage = parent .joinpath (f"garbage-{ uuid .uuid4 ()} " )
260- path .rename (garbage )
261- rm_rf (garbage )
257+ with tempfile .TemporaryDirectory (
258+ prefix = "garbage-" , dir = os .fsdecode (path .parent )
259+ ) as garbage :
260+ path .replace (garbage )
262261 except OSError :
263262 # known races:
264263 # * other process did a cleanup at the same time
Original file line number Diff line number Diff line change @@ -435,10 +435,29 @@ def test(tmp_path):
435435 fn.write_text('hello')
436436 mode = os.stat(str(fn)).st_mode
437437 os.chmod(str(fn), mode & ~stat.S_IREAD)
438- """
438+ """
439439 )
440440 result = testdir .runpytest ("--basetemp=tmp" )
441441 assert result .ret == 0
442442 # running a second time and ensure we don't crash
443443 result = testdir .runpytest ("--basetemp=tmp" )
444444 assert result .ret == 0
445+
446+
447+ def test_basetemp_with_not_executable_dirs (testdir ):
448+ """Integration test for #7940"""
449+ testdir .makepyfile (
450+ """
451+ def test(tmp_path):
452+ p = tmp_path / "ham" / "spam" / "eggs"
453+ p.parent.mkdir(parents=True)
454+ p.touch(mode=0)
455+ for p in p.parents:
456+ if p == tmp_path:
457+ break
458+ p.chmod(mode=0)
459+ """
460+ )
461+ assert testdir .runpytest ("--basetemp=tmp" ).ret == 0
462+ # running a second time and ensure we don't crash
463+ assert testdir .runpytest ("--basetemp=tmp" ).ret == 0
You can’t perform that action at this time.
0 commit comments