From b82d6f7a0b628a5f1cb6d326ec25389f3c804abf Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Tue, 2 Oct 2018 08:34:02 +0200 Subject: [PATCH] pytester: use per test tmproot --- src/_pytest/pytester.py | 3 +++ src/_pytest/tmpdir.py | 4 +++- testing/test_tmpdir.py | 2 -- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 85f824784..228f9a193 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -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 diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index 422f1f7fb..7b5f6510e 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -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 diff --git a/testing/test_tmpdir.py b/testing/test_tmpdir.py index db1e8b00c..9244e309d 100644 --- a/testing/test_tmpdir.py +++ b/testing/test_tmpdir.py @@ -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():