Skip to content

Commit

Permalink
Merge pull request #4681 from RonnyPfannschmidt/fix-4680-tmppath-is-t…
Browse files Browse the repository at this point in the history
…mpdir

Fix 4680 - `tmp_path` and `tmpdir` now share the same temporary directory
  • Loading branch information
nicoddemus authored Jan 29, 2019
2 parents 6aba60a + 2d7582b commit 7ad499a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog/4680.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure the ``tmpdir`` and the ``tmp_path`` fixtures are the same folder.
1 change: 1 addition & 0 deletions changelog/4681.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure ``tmp_path`` is always a real path.
7 changes: 4 additions & 3 deletions src/_pytest/tmpdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ def getbasetemp(self):
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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testing/python/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def sarg(tmpdir):
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()
Expand Down
4 changes: 4 additions & 0 deletions testing/test_tmpdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7ad499a

Please sign in to comment.