diff --git a/py/test/config.py b/py/test/config.py index 08ac4057e..db4af0e1e 100644 --- a/py/test/config.py +++ b/py/test/config.py @@ -8,12 +8,15 @@ optparse = py.compat.optparse # XXX move to Config class basetemp = None +_pid = None def ensuretemp(string, dir=1): """ return temporary directory path with the given string as the trailing part. """ - global basetemp - if basetemp is None: + global basetemp, _pid + currpid = py.std.os.getpid() + if basetemp is None or _pid != currpid: + _pid = currpid basetemp = py.path.local.make_numbered_dir(prefix='pytest-') return basetemp.ensure(string, dir=dir) diff --git a/py/test/testing/test_config.py b/py/test/testing/test_config.py index 275f57503..0bde2f057 100644 --- a/py/test/testing/test_config.py +++ b/py/test/testing/test_config.py @@ -10,6 +10,21 @@ def test_tmpdir(): assert d1 == d2 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(): o = py.test.ensuretemp('configoptions') o.ensure("conftest.py").write(py.code.Source("""