Skip to content

Commit

Permalink
Factor out a function for repeat_rmtree
Browse files Browse the repository at this point in the history
  • Loading branch information
itziakos committed Aug 17, 2024
1 parent 1fcd373 commit 39d8f50
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 10 additions & 0 deletions zipfile2/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import shutil
import unittest

HERE = os.path.dirname(__file__)
Expand Down Expand Up @@ -196,3 +197,12 @@ def skip_unless_symlink(test):
ok = can_symlink()
msg = "Requires functional symlink implementation"
return test if ok else unittest.skip(msg)(test)


def repeat_rmtree(*args, **kwargs):
# Windows rmtree might fail the first time
for _ in range(5):
try:
shutil.rmtree(*args, **kwargs)
except Exception:
pass
13 changes: 4 additions & 9 deletions zipfile2/tests/test__zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .common import (
NOSE_EGG, VTK_EGG, ZIP_WITH_DIRECTORY_SOFTLINK, ZIP_WITH_SOFTLINK,
ZIP_WITH_PERMISSIONS, ZIP_WITH_SOFTLINK_AND_PERMISSIONS,
skip_unless_symlink)
skip_unless_symlink, repeat_rmtree)


HERE = os.path.dirname(__file__)
Expand Down Expand Up @@ -72,8 +72,8 @@ def setUp(self):
self.tempdir2 = tempfile.mkdtemp()

def tearDown(self):
shutil.rmtree(self.tempdir2)
shutil.rmtree(self.tempdir)
repeat_rmtree(self.tempdir2)
repeat_rmtree(self.tempdir)

def test_simple(self):
# Given
Expand Down Expand Up @@ -577,12 +577,7 @@ def setUp(self):
os.remove(path)

def tearDown(self):
# Windows rmtree might fail the first time
for _ in range(5):
try:
shutil.rmtree(self.tempdir, onerror=handle_readonly)
except Exception:
pass
repeat_rmtree(self.tempdir, onerror=handle_readonly)

def test_extractall_preserve_none(self):
umask = os.umask(0)
Expand Down

0 comments on commit 39d8f50

Please sign in to comment.