From f9d51270215ce354f8f8ab4fedd4ed7ea0996bb5 Mon Sep 17 00:00:00 2001 From: Michael Abel Date: Tue, 16 Jul 2019 13:24:08 +0200 Subject: [PATCH 1/8] Register cleanup_numbered_dir for atexit before the cleanup for locks is registered (#1120) The cleanup of the numbered directory will now be executed after the locks of the current process got removed. --- src/_pytest/pathlib.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index 8d25b21dd7d..54cd74e71cb 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -299,12 +299,13 @@ def make_numbered_dir_with_cleanup( for i in range(10): try: p = make_numbered_dir(root, prefix) + consider_lock_dead_if_created_before = p.stat().st_mtime - lock_timeout lock_path = create_cleanup_lock(p) + atexit.register(cleanup_numbered_dir, root, prefix, keep, consider_lock_dead_if_created_before) 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, From 3d5d0aca6aa4239206906fc351ed8895089d8ce2 Mon Sep 17 00:00:00 2001 From: Michael Abel Date: Tue, 16 Jul 2019 13:26:11 +0200 Subject: [PATCH 2/8] Add comments to clarify directory cleanup --- src/_pytest/pathlib.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index 54cd74e71cb..fb089016ba7 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -301,11 +301,13 @@ def make_numbered_dir_with_cleanup( p = make_numbered_dir(root, prefix) consider_lock_dead_if_created_before = p.stat().st_mtime - lock_timeout lock_path = create_cleanup_lock(p) + # Register a cleanup for program exit atexit.register(cleanup_numbered_dir, root, prefix, keep, consider_lock_dead_if_created_before) register_cleanup_lock_removal(lock_path) except Exception as exc: e = exc else: + # Cleanup now at the beginning of the test execution cleanup_numbered_dir( root=root, prefix=prefix, From 02137405f9de1fef3786b17531e9924aa15f6f1a Mon Sep 17 00:00:00 2001 From: Michael Abel Date: Tue, 16 Jul 2019 13:35:30 +0200 Subject: [PATCH 3/8] Remove obsolete cleanup at program start --- src/_pytest/pathlib.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index fb089016ba7..66f2bff68da 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -307,13 +307,6 @@ def make_numbered_dir_with_cleanup( except Exception as exc: e = exc else: - # Cleanup now at the beginning of the test execution - cleanup_numbered_dir( - root=root, - prefix=prefix, - keep=keep, - consider_lock_dead_if_created_before=consider_lock_dead_if_created_before, - ) return p assert e is not None raise e From 9439e07e2740af2fcf37b97dc0076a900e8d3b75 Mon Sep 17 00:00:00 2001 From: Michael Abel Date: Wed, 17 Jul 2019 21:24:16 +0200 Subject: [PATCH 4/8] Linting autoformat --- src/_pytest/pathlib.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index 66f2bff68da..9d82bf8d755 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -302,7 +302,13 @@ def make_numbered_dir_with_cleanup( consider_lock_dead_if_created_before = p.stat().st_mtime - lock_timeout lock_path = create_cleanup_lock(p) # Register a cleanup for program exit - atexit.register(cleanup_numbered_dir, root, prefix, keep, consider_lock_dead_if_created_before) + atexit.register( + cleanup_numbered_dir, + root, + prefix, + keep, + consider_lock_dead_if_created_before, + ) register_cleanup_lock_removal(lock_path) except Exception as exc: e = exc From 7dee7fc96615c2d2961b8ab054b6b5a05c168024 Mon Sep 17 00:00:00 2001 From: Michael Abel Date: Wed, 17 Jul 2019 21:28:40 +0200 Subject: [PATCH 5/8] Add changelog entry --- changelog/1120.bugfix.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelog/1120.bugfix.rst diff --git a/changelog/1120.bugfix.rst b/changelog/1120.bugfix.rst new file mode 100644 index 00000000000..6f04e09462f --- /dev/null +++ b/changelog/1120.bugfix.rst @@ -0,0 +1,2 @@ +Fix issue where directories from ``tmpdir`` are not removed properly when +multiple instances of pytest are running in parallel. From 3e071347abad3bb47b7c863a2f417e30eac6daad Mon Sep 17 00:00:00 2001 From: Michael Abel Date: Wed, 17 Jul 2019 21:29:22 +0200 Subject: [PATCH 6/8] Update AUTHORS file --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 14c46557129..bedb1e7b786 100644 --- a/AUTHORS +++ b/AUTHORS @@ -177,6 +177,7 @@ Matt Williams Matthias Hafner Maxim Filipenko mbyt +Michael Abel Michael Aquilina Michael Birtwell Michael Droettboom From 5eb46e30f072079fee110176e1bd58274b4d0e7d Mon Sep 17 00:00:00 2001 From: Caitlin Macleod Date: Thu, 21 Nov 2019 20:03:08 +1100 Subject: [PATCH 7/8] Move at_exit registration outside numbered dir loop --- src/_pytest/pathlib.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index 9d82bf8d755..a290b3dfa32 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -296,19 +296,19 @@ def make_numbered_dir_with_cleanup( ) -> Path: """creates a numbered dir with a cleanup lock and removes old ones""" e = None + # Register a cleanup for program exit + consider_lock_dead_if_created_before = p.stat().st_mtime - lock_timeout + atexit.register( + cleanup_numbered_dir, + root, + prefix, + keep, + consider_lock_dead_if_created_before, + ) for i in range(10): try: p = make_numbered_dir(root, prefix) - consider_lock_dead_if_created_before = p.stat().st_mtime - lock_timeout lock_path = create_cleanup_lock(p) - # Register a cleanup for program exit - atexit.register( - cleanup_numbered_dir, - root, - prefix, - keep, - consider_lock_dead_if_created_before, - ) register_cleanup_lock_removal(lock_path) except Exception as exc: e = exc From 137a2a7f54dc764061ff002f2f27c1d9316451f6 Mon Sep 17 00:00:00 2001 From: Caitlin Macleod Date: Thu, 21 Nov 2019 20:03:53 +1100 Subject: [PATCH 8/8] Add caitlin to the AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index bedb1e7b786..75f292dcf3c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -47,6 +47,7 @@ Brian Maissy Brian Okken Brianna Laugher Bruno Oliveira +Caitlin Macleod Cal Leeming Carl Friedrich Bolz Carlos Jenkins