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