diff --git a/py/_path/local.py b/py/_path/local.py index 2687d060f..460a963a6 100644 --- a/py/_path/local.py +++ b/py/_path/local.py @@ -628,12 +628,14 @@ class LocalPath(FSBase): return py.path.local(py.std.tempfile.gettempdir()) get_temproot = classmethod(get_temproot) - def mkdtemp(cls): + def mkdtemp(cls, rootdir=None): """ return a Path object pointing to a fresh new temporary directory (which we created ourself). """ import tempfile - return cls(py.error.checked_call(tempfile.mkdtemp)) + if rootdir is None: + rootdir = cls.get_temproot() + return cls(py.error.checked_call(tempfile.mkdtemp, dir=str(rootdir))) mkdtemp = classmethod(mkdtemp) def make_numbered_dir(cls, prefix='session-', rootdir=None, keep=3, diff --git a/testing/path/test_local.py b/testing/path/test_local.py index f60eb1436..8aeb36ff3 100644 --- a/testing/path/test_local.py +++ b/testing/path/test_local.py @@ -389,6 +389,10 @@ def test_samefile(tmpdir): p = tmpdir.ensure("hello") assert p.samefile(p) +def test_mkdtemp_rootdir(tmpdir): + dtmp = local.mkdtemp(rootdir=tmpdir) + assert tmpdir.listdir() == [dtmp] + class TestWINLocalPath: pytestmark = win32only