[svn r38214] be a bit nicer: don't pollute /tmp with a new tempdir

for each boxed test run.  Also fix the counting
of boxes (how did it ever work like this, anyway)

--HG--
branch : trunk
This commit is contained in:
hpk 2007-02-08 23:24:44 +01:00
parent 999da7a376
commit 07310d0799
1 changed files with 7 additions and 6 deletions

View File

@ -14,11 +14,12 @@ PYTESTSTDERR = "pyteststderr"
PYTESTRETVAL = "pytestretval"
import tempfile
import itertools
from StringIO import StringIO
counter = itertools.count().next
class FileBox(object):
count = 0
def __init__(self, fun, args=None, kwargs=None, config=None):
if args is None:
args = []
@ -32,8 +33,8 @@ class FileBox(object):
def run(self, continuation=False):
# XXX we should not use py.test.ensuretemp here
tempdir = py.test.ensuretemp("box%d" % self.count)
self.count += 1
count = counter()
tempdir = py.test.ensuretemp("box%d" % count)
self.tempdir = tempdir
self.PYTESTRETVAL = tempdir.join('retval')
self.PYTESTSTDOUT = tempdir.join('stdout')
@ -81,10 +82,10 @@ class FileBox(object):
if nice_level:
os.nice(nice_level)
# with fork() we have duplicated py.test's basetemp
# directory so we unset it manually here.
# directory so we set it manually here.
# this may be expensive for some test setups,
# but that is what you get with boxing.
pytestconfig.basetemp = None
pytestconfig.basetemp = self.tempdir.join("childbasetemp")
retval = self.fun(*self.args, **self.kwargs)
retvalf.write(marshal.dumps(retval))
finally: