pytester: use per test tmproot

This commit is contained in:
Ronny Pfannschmidt 2018-10-02 08:34:02 +02:00
parent 4a436b5470
commit b82d6f7a0b
3 changed files with 6 additions and 3 deletions

View File

@ -496,6 +496,8 @@ class Testdir(object):
self._mod_collections = WeakKeyDictionary()
name = request.function.__name__
self.tmpdir = tmpdir_factory.mktemp(name, numbered=True)
self.test_tmproot = tmpdir_factory.mktemp("tmp-" + name, numbered=True)
os.environ["PYTEST_DEBUG_TEMPROOT"] = str(self.test_tmproot)
self.plugins = []
self._cwd_snapshot = CwdSnapshot()
self._sys_path_snapshot = SysPathsSnapshot()
@ -522,6 +524,7 @@ class Testdir(object):
self._sys_modules_snapshot.restore()
self._sys_path_snapshot.restore()
self._cwd_snapshot.restore()
del os.environ["PYTEST_DEBUG_TEMPROOT"]
def __take_sys_modules_snapshot(self):
# some zope modules used by twisted-related tests keep internal state

View File

@ -1,6 +1,7 @@
""" support for providing temporary directories to test functions. """
from __future__ import absolute_import, division, print_function
import os
import re
import pytest
import py
@ -51,7 +52,8 @@ class TempPathFactory(object):
basetemp = Path(self.given_basetemp)
ensure_reset_dir(basetemp)
else:
temproot = Path(tempfile.gettempdir())
from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT")
temproot = Path(from_env or tempfile.gettempdir())
user = get_user() or "unknown"
# use a sub-directory in the temproot to speed-up
# make_numbered_dir() call

View File

@ -143,7 +143,6 @@ def break_getuser(monkeypatch):
monkeypatch.delenv(envvar, raising=False)
@pytest.mark.skip(reason="creates random tmpdirs as part of a system level test")
@pytest.mark.usefixtures("break_getuser")
@pytest.mark.skipif(sys.platform.startswith("win"), reason="no os.getuid on windows")
def test_tmpdir_fallback_uid_not_found(testdir):
@ -162,7 +161,6 @@ def test_tmpdir_fallback_uid_not_found(testdir):
reprec.assertoutcome(passed=1)
@pytest.mark.skip(reason="creates random tmpdirs as part of a system level test")
@pytest.mark.usefixtures("break_getuser")
@pytest.mark.skipif(sys.platform.startswith("win"), reason="no os.getuid on windows")
def test_get_user_uid_not_found():