Skip to content

Commit 2bed8f2

Browse files
test(release_homebrew): Handle read-only files when removing test repo
Add logic to make files writable and retry removal to fix teardown failures. Imported stat and added _make_writable_and_retry (used as shutil.rmtree onexc handler) and _remove_test_repo which ensures cwd is reset and uses onexc to handle permission errors. The homebrew_core_fork_repo fixture teardown now calls _remove_test_repo instead of a plain shutil.rmtree to reliably delete the test repository.
1 parent 5390529 commit 2bed8f2

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

tests/release_homebrew/conftest.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# standard imports
22
import os
33
import shutil
4+
import stat
45
import subprocess
56
import sys
67

@@ -195,7 +196,18 @@ def org_homebrew_repo():
195196
yield repo_directory
196197

197198

198-
@pytest.fixture(scope='function') # todo: fix repo deletion
199+
def _make_writable_and_retry(function, path, _exc_info):
200+
os.chmod(path, os.stat(path).st_mode | stat.S_IWRITE)
201+
function(path)
202+
203+
204+
def _remove_test_repo(repo_directory):
205+
if os.path.isdir(repo_directory):
206+
os.chdir(og_dir)
207+
shutil.rmtree(repo_directory, onexc=_make_writable_and_retry)
208+
209+
210+
@pytest.fixture(scope='function')
199211
def homebrew_core_fork_repo():
200212
directory = os.path.join(os.environ['GITHUB_WORKSPACE'], 'release_homebrew_action')
201213
os.makedirs(directory, exist_ok=True)
@@ -234,8 +246,8 @@ def homebrew_core_fork_repo():
234246

235247
yield repo_directory
236248

237-
# remove the homebrew-core fork (this fails)
238-
# shutil.rmtree(repo_directory)
249+
# remove the homebrew-core fork
250+
_remove_test_repo(repo_directory)
239251

240252

241253
def _cleanup_bottle_files():

0 commit comments

Comments
 (0)