From bde0ebcda91637366d84fa2c526acb33663c9d22 Mon Sep 17 00:00:00 2001 From: piotrhm Date: Fri, 20 Mar 2020 15:38:55 +0100 Subject: [PATCH 1/3] 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 fdcd5b6e0..821a7d8f4 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 000000000..96d9887d7 --- /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 69f490a1d..8c68fe9e5 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 From f0e47c1ed6b89a5111f5f0a48c600ad91de5b767 Mon Sep 17 00:00:00 2001 From: piotrhm Date: Fri, 20 Mar 2020 16:49:00 +0100 Subject: [PATCH 2/3] Fix typo --- src/_pytest/pathlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index 8c68fe9e5..29d8c4dc9 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -333,7 +333,7 @@ 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: From e862643b3fb701db040ca000041915984ae64a22 Mon Sep 17 00:00:00 2001 From: piotrhm Date: Sun, 22 Mar 2020 11:28:24 +0100 Subject: [PATCH 3/3] Update 1120.bugfix.rst --- changelog/1120.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/1120.bugfix.rst b/changelog/1120.bugfix.rst index 96d9887d7..95e74fa75 100644 --- a/changelog/1120.bugfix.rst +++ b/changelog/1120.bugfix.rst @@ -1 +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 +Fix issue where directories from tmpdir are not removed properly when multiple instances of pytest are running in parallel.