Skip to content

Commit

Permalink
Fixes #4653 - tmp_path provides real path
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau committed Jan 18, 2019
1 parent 6154a5a commit 04bd147
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -7,6 +7,7 @@ Aaron Coleman
Abdeali JK
Abhijeet Kasurde
Adam Johnson
Adam Uhlir
Ahn Ki-Wook
Alan Velasco
Alexander Johnson
Expand Down
1 change: 1 addition & 0 deletions changelog/4653.bugfix.rst
@@ -0,0 +1 @@
``tmp_path`` fixture and other related ones provides resolved path (a.k.a real path)
2 changes: 1 addition & 1 deletion src/_pytest/tmpdir.py
Expand Up @@ -65,7 +65,7 @@ def getbasetemp(self):
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
Expand Down
16 changes: 16 additions & 0 deletions testing/test_tmpdir.py
Expand Up @@ -121,6 +121,22 @@ def test_1(tmpdir):
assert not result.ret


def test_tmp_path_always_is_realpath(testdir, monkeypatch):
# for reasoning see: test_tmpdir_always_is_realpath test-case
realtemp = testdir.tmpdir.mkdir("myrealtemp")
linktemp = testdir.tmpdir.join("symlinktemp")
attempt_symlink_to(linktemp, str(realtemp))
monkeypatch.setenv("PYTEST_DEBUG_TEMPROOT", str(linktemp))
testdir.makepyfile(
"""
def test_1(tmp_path):
assert tmp_path.resolve() == tmp_path
"""
)
reprec = testdir.inline_run()
reprec.assertoutcome(passed=1)


def test_tmpdir_too_long_on_parametrization(testdir):
testdir.makepyfile(
"""
Expand Down

0 comments on commit 04bd147

Please sign in to comment.