test(git): close test repositories instead of rmtree so teardown works on Windows - #4880
Open
tsurutanmen wants to merge 1 commit into
Open
tsurutanmen wants to merge 1 commit into
tsurutanmen wants to merge 1 commit into
Conversation
…s on Windows On Windows the test_repository fixture teardown raised PermissionError for 40 of 87 tests: shutil.rmtree ran while GitPython still held handles (WinError 32), and git's loose object files are read-only, which rmtree cannot delete (WinError 5). Close the repo to release its handles and leave tmp_path removal to pytest, which handles read-only files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On Windows, 40 of the 87 tests in
src/giterror during teardown of thetest_repositoryfixture. The assertions pass, but pytest reportsPermissionErrorfromshutil.rmtree(repo_path):[WinError 32](file in use): GitPython still holds handles, such as its persistentgit cat-fileprocesses, when the fixture removes the directory.[WinError 5](access denied): git writes loose object files as read-only, andshutil.rmtreecannot delete read-only files on Windows. This shows up in the twogit_addtests, where the git CLI writes the objects.This PR calls
test_repo.close()to release the handles, and drops the explicitrmtree. The repository lives under pytest'stmp_path, and pytest removes that directory itself, including read-only files.Server Details
Motivation and Context
Contributors on Windows currently see 40 errors from a clean checkout. That makes it hard to tell whether a change broke anything.
How Has This Been Tested?
On Windows 11, Python 3.11, git for Windows:
47 passed, 40 errors47 passedruff checkandpyrightare clean. There are no behavior changes on Linux or macOS:close()is a no-op there apart from releasing resources, andtmp_pathcleanup already applies.Breaking Changes
None. Only tests change.
Types of changes
Checklist
Additional context
I found this while working on #4879, which also touches this server.
🤖 Generated with Claude Code