Skip to content

Commit bde0ebc

Browse files
piotrhmnicoddemus
authored andcommitted
Replace cleanup_numbered_dir with atexit.register
1 parent c871d8b commit bde0ebc

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ Pedro Algarvio
227227
Philipp Loose
228228
Pieter Mulder
229229
Piotr Banaszkiewicz
230+
Piotr Helm
230231
Prashant Anand
231232
Pulkit Goyal
232233
Punyashloka Biswal

changelog/1120.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix issue where directories from tmpdir are not removed properly when multiple instances of pytest are running in parallel.

src/_pytest/pathlib.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,18 @@ def make_numbered_dir_with_cleanup(
333333
try:
334334
p = make_numbered_dir(root, prefix)
335335
lock_path = create_cleanup_lock(p)
336-
register_cleanup_lock_removal(lock_path)
336+
register_cleanup_lock_removal(lock_path)
337337
except Exception as exc:
338338
e = exc
339339
else:
340340
consider_lock_dead_if_created_before = p.stat().st_mtime - lock_timeout
341-
cleanup_numbered_dir(
342-
root=root,
343-
prefix=prefix,
344-
keep=keep,
345-
consider_lock_dead_if_created_before=consider_lock_dead_if_created_before,
341+
# Register a cleanup for program exit
342+
atexit.register(
343+
cleanup_numbered_dir,
344+
root,
345+
prefix,
346+
keep,
347+
consider_lock_dead_if_created_before,
346348
)
347349
return p
348350
assert e is not None

0 commit comments

Comments
 (0)