From 04bd147d46033511401d3b06f4fcc8b49205fb9a Mon Sep 17 00:00:00 2001 From: Adam Uhlir Date: Fri, 18 Jan 2019 12:54:00 -0800 Subject: [PATCH] Fixes #4653 - tmp_path provides real path --- AUTHORS | 1 + changelog/4653.bugfix.rst | 1 + src/_pytest/tmpdir.py | 2 +- testing/test_tmpdir.py | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 changelog/4653.bugfix.rst diff --git a/AUTHORS b/AUTHORS index 68298ba80..5c8cd9c9e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -7,6 +7,7 @@ Aaron Coleman Abdeali JK Abhijeet Kasurde Adam Johnson +Adam Uhlir Ahn Ki-Wook Alan Velasco Alexander Johnson diff --git a/changelog/4653.bugfix.rst b/changelog/4653.bugfix.rst new file mode 100644 index 000000000..5b5b36745 --- /dev/null +++ b/changelog/4653.bugfix.rst @@ -0,0 +1 @@ +``tmp_path`` fixture and other related ones provides resolved path (a.k.a real path) diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index 860c2d4af..6c140d1d5 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -65,7 +65,7 @@ class TempPathFactory(object): 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 diff --git a/testing/test_tmpdir.py b/testing/test_tmpdir.py index 6040d9444..f49691dad 100644 --- a/testing/test_tmpdir.py +++ b/testing/test_tmpdir.py @@ -121,6 +121,22 @@ def test_tmpdir_always_is_realpath(testdir): 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( """