Merge pull request #4654 from AuHau/fix/#4653-Fix_tmp_path_symlink_resolution

Fixes #4653 - tmp_path provides real path
This commit is contained in:
Bruno Oliveira 2019-01-19 09:41:47 -02:00 committed by GitHub
commit 57bf9d6740
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View File

@ -7,6 +7,7 @@ Aaron Coleman
Abdeali JK Abdeali JK
Abhijeet Kasurde Abhijeet Kasurde
Adam Johnson Adam Johnson
Adam Uhlir
Ahn Ki-Wook Ahn Ki-Wook
Alan Velasco Alan Velasco
Alexander Johnson Alexander Johnson

View File

@ -0,0 +1 @@
``tmp_path`` fixture and other related ones provides resolved path (a.k.a real path)

View File

@ -65,7 +65,7 @@ class TempPathFactory(object):
ensure_reset_dir(basetemp) ensure_reset_dir(basetemp)
else: else:
from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT") 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" user = get_user() or "unknown"
# use a sub-directory in the temproot to speed-up # use a sub-directory in the temproot to speed-up
# make_numbered_dir() call # make_numbered_dir() call

View File

@ -121,6 +121,22 @@ def test_tmpdir_always_is_realpath(testdir):
assert not result.ret 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): def test_tmpdir_too_long_on_parametrization(testdir):
testdir.makepyfile( testdir.makepyfile(
""" """