From bde0ebcda91637366d84fa2c526acb33663c9d22 Mon Sep 17 00:00:00 2001 From: piotrhm Date: Fri, 20 Mar 2020 15:38:55 +0100 Subject: [PATCH] Replace cleanup_numbered_dir with atexit.register --- AUTHORS | 1 + changelog/1120.bugfix.rst | 1 + src/_pytest/pathlib.py | 14 ++++++++------ 3 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 changelog/1120.bugfix.rst diff --git a/AUTHORS b/AUTHORS index fdcd5b6e047..821a7d8f41e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -227,6 +227,7 @@ Pedro Algarvio Philipp Loose Pieter Mulder Piotr Banaszkiewicz +Piotr Helm Prashant Anand Pulkit Goyal Punyashloka Biswal diff --git a/changelog/1120.bugfix.rst b/changelog/1120.bugfix.rst new file mode 100644 index 00000000000..96d9887d746 --- /dev/null +++ b/changelog/1120.bugfix.rst @@ -0,0 +1 @@ +Fix issue where directories from tmpdir are not removed properly when multiple instances of pytest are running in parallel. \ No newline at end of file diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index 69f490a1d48..8c68fe9e5d3 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -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