Commit 5c1767ae authored by Jim Fulton's avatar Jim Fulton

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.
parent 15a8778b
...@@ -18,6 +18,7 @@ $Id$ ...@@ -18,6 +18,7 @@ $Id$
import os import os
import shutil import shutil
import sys
import tempfile import tempfile
import time import time
...@@ -46,11 +47,26 @@ class P(persistent.Persistent): ...@@ -46,11 +47,26 @@ class P(persistent.Persistent):
def setUp(test): def setUp(test):
test.globs['__teardown_stack__'] = [] test.globs['__teardown_stack__'] = []
tmp = tempfile.mkdtemp('test') tmp = tempfile.mkdtemp('test')
registerTearDown(test, lambda : shutil.rmtree(tmp)) registerTearDown(test, lambda : rmtree(tmp))
here = os.getcwd() here = os.getcwd()
registerTearDown(test, lambda : os.chdir(here)) registerTearDown(test, lambda : os.chdir(here))
os.chdir(tmp) 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): def registerTearDown(test, func):
test.globs['__teardown_stack__'].append(func) test.globs['__teardown_stack__'].append(func)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment