[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/tests/util.py Added code
to wait if attempts to remove the test dir fail on windows
Jim Fulton
jim at zope.com
Sat May 12 10:18:06 EDT 2007
Log message for revision 75702:
Added code to wait if attempts to remove the test dir fail on windows
to give time for servers to stop, since windows won't let us remove
files or directories if they are in use.
Changed:
U ZODB/trunk/src/ZODB/tests/util.py
-=-
Modified: ZODB/trunk/src/ZODB/tests/util.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/util.py 2007-05-12 13:50:18 UTC (rev 75701)
+++ ZODB/trunk/src/ZODB/tests/util.py 2007-05-12 14:18:05 UTC (rev 75702)
@@ -18,6 +18,7 @@
import os
import shutil
+import sys
import tempfile
import time
@@ -46,11 +47,26 @@
def setUp(test):
test.globs['__teardown_stack__'] = []
tmp = tempfile.mkdtemp('test')
- registerTearDown(test, lambda : shutil.rmtree(tmp))
+ registerTearDown(test, lambda : rmtree(tmp))
here = os.getcwd()
registerTearDown(test, lambda : os.chdir(here))
os.chdir(tmp)
-
+
+if sys.platform == 'win32':
+ # On windows, we can't remove a directory of there are files upen.
+ # We may need to wait a while for processes to exit.
+ def rmtree(path):
+ for i in range(1000):
+ try:
+ shutil.rmtree(path)
+ except OSError:
+ time.sleep(0.01)
+ else:
+ break
+
+else:
+ rmtree = shutil.rmtree
+
def registerTearDown(test, func):
test.globs['__teardown_stack__'].append(func)
More information about the Zodb-checkins
mailing list