[svn r38182] Made that ensuretemp() creates a new dir after forks.

--HG--
branch : trunk
This commit is contained in:
guido 2007-02-08 18:25:32 +01:00
parent 1e8845dfa5
commit e89d5e5880
2 changed files with 20 additions and 2 deletions

View File

@ -8,12 +8,15 @@ optparse = py.compat.optparse
# XXX move to Config class # XXX move to Config class
basetemp = None basetemp = None
_pid = None
def ensuretemp(string, dir=1): def ensuretemp(string, dir=1):
""" return temporary directory path with """ return temporary directory path with
the given string as the trailing part. the given string as the trailing part.
""" """
global basetemp global basetemp, _pid
if basetemp is None: currpid = py.std.os.getpid()
if basetemp is None or _pid != currpid:
_pid = currpid
basetemp = py.path.local.make_numbered_dir(prefix='pytest-') basetemp = py.path.local.make_numbered_dir(prefix='pytest-')
return basetemp.ensure(string, dir=dir) return basetemp.ensure(string, dir=dir)

View File

@ -10,6 +10,21 @@ def test_tmpdir():
assert d1 == d2 assert d1 == d2
assert d1.check(dir=1) assert d1.check(dir=1)
def test_ensuretemp_fork():
os = py.std.os
org_getpid = os.getpid
currpid = 0
def getpid():
return currpid
try:
os.getpid = getpid
d1 = py.test.ensuretemp('hello')
currpid = 1
d2 = py.test.ensuretemp('hello')
finally:
os.getpid = org_getpid
assert d1 != d2
def test_config_cmdline_options(): def test_config_cmdline_options():
o = py.test.ensuretemp('configoptions') o = py.test.ensuretemp('configoptions')
o.ensure("conftest.py").write(py.code.Source(""" o.ensure("conftest.py").write(py.code.Source("""