Merge pull request #4681 from RonnyPfannschmidt/fix-4680-tmppath-is-tmpdir

Fix 4680 - `tmp_path` and `tmpdir` now share the same temporary directory
This commit is contained in:
Bruno Oliveira 2019-01-29 19:00:56 -02:00 committed by GitHub
commit 7ad499ad76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 4 deletions

View File

@ -0,0 +1 @@
Ensure the ``tmpdir`` and the ``tmp_path`` fixtures are the same folder.

View File

@ -0,0 +1 @@
Ensure ``tmp_path`` is always a real path.

View File

@ -63,9 +63,10 @@ class TempPathFactory(object):
if self._given_basetemp is not None: if self._given_basetemp is not None:
basetemp = self._given_basetemp basetemp = self._given_basetemp
ensure_reset_dir(basetemp) ensure_reset_dir(basetemp)
basetemp = basetemp.resolve()
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
@ -167,7 +168,7 @@ def _mk_tmp(request, factory):
@pytest.fixture @pytest.fixture
def tmpdir(request, tmpdir_factory): def tmpdir(tmp_path):
"""Return a temporary directory path object """Return a temporary directory path object
which is unique to each test function invocation, which is unique to each test function invocation,
created as a sub directory of the base temporary 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 .. _`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 @pytest.fixture

View File

@ -739,7 +739,7 @@ class TestRequestBasic(object):
def test_function(request, farg): def test_function(request, farg):
assert set(get_public_names(request.fixturenames)) == \ assert set(get_public_names(request.fixturenames)) == \
set(["tmpdir", "sarg", "arg1", "request", "farg", set(["tmpdir", "sarg", "arg1", "request", "farg",
"tmpdir_factory"]) "tmp_path", "tmp_path_factory"])
""" """
) )
reprec = testdir.inline_run() reprec = testdir.inline_run()

View File

@ -337,3 +337,7 @@ def attempt_symlink_to(path, to_path):
Path(path).symlink_to(Path(to_path)) Path(path).symlink_to(Path(to_path))
except OSError: except OSError:
pytest.skip("could not create symbolic link") pytest.skip("could not create symbolic link")
def test_tmpdir_equals_tmp_path(tmpdir, tmp_path):
assert Path(tmpdir) == tmp_path