Skip to content

Commit

Permalink
Replace cleanup_numbered_dir with atexit.register
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrhm authored and nicoddemus committed Jun 9, 2020
1 parent c871d8b commit bde0ebc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ Pedro Algarvio
Philipp Loose
Pieter Mulder
Piotr Banaszkiewicz
Piotr Helm
Prashant Anand
Pulkit Goyal
Punyashloka Biswal
Expand Down
1 change: 1 addition & 0 deletions changelog/1120.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issue where directories from tmpdir are not removed properly when multiple instances of pytest are running in parallel.
14 changes: 8 additions & 6 deletions src/_pytest/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,18 @@ def make_numbered_dir_with_cleanup(
try:
p = make_numbered_dir(root, prefix)
lock_path = create_cleanup_lock(p)
register_cleanup_lock_removal(lock_path)
register_cleanup_lock_removal(lock_path)
except Exception as exc:
e = exc
else:
consider_lock_dead_if_created_before = p.stat().st_mtime - lock_timeout
cleanup_numbered_dir(
root=root,
prefix=prefix,
keep=keep,
consider_lock_dead_if_created_before=consider_lock_dead_if_created_before,
# Register a cleanup for program exit
atexit.register(
cleanup_numbered_dir,
root,
prefix,
keep,
consider_lock_dead_if_created_before,
)
return p
assert e is not None
Expand Down

0 comments on commit bde0ebc

Please sign in to comment.