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/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 860c2d4af..843c8ca37 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -63,9 +63,10 @@ class TempPathFactory(object): if self._given_basetemp is not None: 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()) + 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 @@ -167,7 +168,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 +177,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/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() 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