From f62df523e0121ddead413da6d6eaf944a39c74e5 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Tue, 12 Dec 2023 09:15:19 -0500 Subject: [PATCH 1/2] Remove TestSubmodule.test_rename xfail mark This is to clearly establish the failure still occurs (since we do not have strict=True set). It is in preparation for working around the problems with a call to gc.collect(). See 82c361e and 0b7ee17 for context. --- test/test_submodule.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test/test_submodule.py b/test/test_submodule.py index 852a5ef6f..e2380d522 100644 --- a/test/test_submodule.py +++ b/test/test_submodule.py @@ -948,18 +948,6 @@ def test_remove_norefs(self, rwdir): sm.remove() assert not sm.exists() - @pytest.mark.xfail( - os.name == "nt" and sys.version_info >= (3, 12), - reason=( - "The sm.move call fails. Submodule.move calls os.renames, which raises:\n" - "PermissionError: [WinError 32] " - "The process cannot access the file because it is being used by another process: " - R"'C:\Users\ek\AppData\Local\Temp\test_renamekkbznwjp\parent\mymodules\myname' " - R"-> 'C:\Users\ek\AppData\Local\Temp\test_renamekkbznwjp\parent\renamed\myname'" - "\nThis resembles other Windows errors, but only occurs starting in Python 3.12." - ), - raises=PermissionError, - ) @with_rw_directory def test_rename(self, rwdir): parent = git.Repo.init(osp.join(rwdir, "parent")) From b66be7ca948307460933939bdbebc8f4ed665299 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Tue, 12 Dec 2023 08:04:01 -0500 Subject: [PATCH 2/2] Replace xfail with gc.collect in TestSubmodule.test_rename Like the xfail was, this is conditional, being done only in the specific situation the PermissionError occurs. Besides that it does not always run even on Windows (only in 3.12 and later), this resembles various other conditional and non-conditional gc.collect calls. It had previously appeared to me that two calls to gc.collect were required, but I am unable to reproduce that. It may have been specific to how I was running it on my system at that time. The need for only one call may have been brought about by changes to the code in the mean time, but I have tested that only one call appears required even without the changes in #1765. --- test/test_submodule.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/test_submodule.py b/test/test_submodule.py index e2380d522..4dc89f98f 100644 --- a/test/test_submodule.py +++ b/test/test_submodule.py @@ -958,6 +958,12 @@ def test_rename(self, rwdir): assert sm.rename(sm_name) is sm and sm.name == sm_name assert not sm.repo.is_dirty(index=True, working_tree=False, untracked_files=False) + # This is needed to work around a PermissionError on Windows, resembling others, + # except new in Python 3.12. (*Maybe* this could be due to changes in CPython's + # garbage collector detailed in https://github.com/python/cpython/issues/97922.) + if os.name == "nt" and sys.version_info >= (3, 12): + gc.collect() + new_path = "renamed/myname" assert sm.move(new_path).name == new_path