From f7d755552100afe8df3da6da64fff6ac59c52de6 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 27 Jan 2019 13:05:34 +0100 Subject: [PATCH 1/4] fix #4680 - ensure tmpdir and tmp_path are the same --- changelog/4680.bugfix.rst | 1 + src/_pytest/tmpdir.py | 4 ++-- testing/test_tmpdir.py | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelog/4680.bugfix.rst diff --git a/changelog/4680.bugfix.rst b/changelog/4680.bugfix.rst new file mode 100644 index 000000000..9126a70ea --- /dev/null +++ b/changelog/4680.bugfix.rst @@ -0,0 +1 @@ +Ensure the ``tmpdir`` and the ``tmp_path`` fixtures are the same folder. diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index 860c2d4af..267328414 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -167,7 +167,7 @@ def _mk_tmp(request, factory): @pytest.fixture -def tmpdir(request, tmpdir_factory): +def tmpdir(tmp_path): """Return a temporary directory path object which is unique to each test function invocation, created as a sub directory of the base temporary @@ -176,7 +176,7 @@ def tmpdir(request, tmpdir_factory): .. _`py.path.local`: https://py.readthedocs.io/en/latest/path.html """ - return _mk_tmp(request, tmpdir_factory) + return py.path.local(tmp_path) @pytest.fixture diff --git a/testing/test_tmpdir.py b/testing/test_tmpdir.py index 6040d9444..3e6bde379 100644 --- a/testing/test_tmpdir.py +++ b/testing/test_tmpdir.py @@ -337,3 +337,7 @@ def attempt_symlink_to(path, to_path): Path(path).symlink_to(Path(to_path)) except OSError: pytest.skip("could not create symbolic link") + + +def test_tmpdir_equals_tmp_path(tmpdir, tmp_path): + assert Path(tmpdir) == tmp_path From c75bd0880729e36d58e61a3da8828c3b47edb030 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 27 Jan 2019 14:08:43 +0100 Subject: [PATCH 2/4] ensure tmp_path is always a realpath --- changelog/4681.bugfix.rst | 1 + src/_pytest/tmpdir.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 changelog/4681.bugfix.rst diff --git a/changelog/4681.bugfix.rst b/changelog/4681.bugfix.rst new file mode 100644 index 000000000..3ece27397 --- /dev/null +++ b/changelog/4681.bugfix.rst @@ -0,0 +1 @@ +Ensure ``tmp_path`` is always a real path. diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index 267328414..b8c755ac6 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -61,11 +61,11 @@ class TempPathFactory(object): """ return base temporary directory. """ if self._basetemp is None: if self._given_basetemp is not None: - basetemp = self._given_basetemp + basetemp = self._given_basetemp.resolve() ensure_reset_dir(basetemp) else: from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT") - temproot = Path(from_env or tempfile.gettempdir()) + temproot = Path(from_env or tempfile.gettempdir()).resolve() user = get_user() or "unknown" # use a sub-directory in the temproot to speed-up # make_numbered_dir() call From 5567c772cd23ebab01cfe642e2363bc1661068a3 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 27 Jan 2019 14:19:23 +0100 Subject: [PATCH 3/4] quick&dirty fix fixture tests that rely on tmppath fixture structure --- testing/python/fixture.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/python/fixture.py b/testing/python/fixture.py index 196b28c51..3d557cec8 100644 --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -739,7 +739,7 @@ class TestRequestBasic(object): def test_function(request, farg): assert set(get_public_names(request.fixturenames)) == \ set(["tmpdir", "sarg", "arg1", "request", "farg", - "tmpdir_factory"]) + "tmp_path", "tmp_path_factory"]) """ ) reprec = testdir.inline_run() From 2d7582bd9204797ee01eea62a48e3913b4288274 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Tue, 29 Jan 2019 18:58:00 +0100 Subject: [PATCH 4/4] flip around basetemp folder reset to see if it helps on windows --- src/_pytest/tmpdir.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index b8c755ac6..843c8ca37 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -61,8 +61,9 @@ class TempPathFactory(object): """ return base temporary directory. """ if self._basetemp is None: if self._given_basetemp is not None: - basetemp = self._given_basetemp.resolve() + basetemp = self._given_basetemp ensure_reset_dir(basetemp) + basetemp = basetemp.resolve() else: from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT") temproot = Path(from_env or tempfile.gettempdir()).resolve()