Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 4680 - tmp_path and tmpdir now share the same temporary directory #4681

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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