-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 4425: resolve --basetemp to absolute paths #4427
Changes from all commits
fc61bdd
f180ab3
4f5c153
f1fe9e4
5f1d692
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Ensure we resolve the absolute path when the given ``--basetemp`` is a relative path. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
import sys | ||
|
||
import attr | ||
import six | ||
|
||
import pytest | ||
|
@@ -25,12 +26,29 @@ def test_ensuretemp(recwarn): | |
assert d1.check(dir=1) | ||
|
||
|
||
@attr.s | ||
class FakeConfig(object): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH not sure if this fake actually improves things... the "option returns self" and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its indeed quite a hack, we cant make a sane config object for use in such cases |
||
basetemp = attr.ib() | ||
trace = attr.ib(default=None) | ||
|
||
@property | ||
def trace(self): | ||
return self | ||
|
||
def get(self, key): | ||
return lambda *k: None | ||
|
||
@property | ||
def option(self): | ||
return self | ||
|
||
|
||
class TestTempdirHandler(object): | ||
def test_mktemp(self, testdir): | ||
def test_mktemp(self, tmp_path): | ||
|
||
from _pytest.tmpdir import TempdirFactory, TempPathFactory | ||
|
||
config = testdir.parseconfig() | ||
config.option.basetemp = testdir.mkdir("hello") | ||
config = FakeConfig(tmp_path) | ||
t = TempdirFactory(TempPathFactory.from_config(config)) | ||
tmp = t.mktemp("world") | ||
assert tmp.relto(t.getbasetemp()) == "world0" | ||
|
@@ -40,6 +58,15 @@ def test_mktemp(self, testdir): | |
assert tmp2.relto(t.getbasetemp()).startswith("this") | ||
assert tmp2 != tmp | ||
|
||
@pytest.mark.issue(4425) | ||
def test_tmppath_relative_basetemp_absolute(self, tmp_path, monkeypatch): | ||
from _pytest.tmpdir import TempPathFactory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a docstring and a reference to the bug. 👍 |
||
|
||
monkeypatch.chdir(tmp_path) | ||
config = FakeConfig("hello") | ||
t = TempPathFactory.from_config(config) | ||
assert t.getbasetemp().resolve() == (tmp_path / "hello").resolve() | ||
|
||
|
||
class TestConfigTmpdir(object): | ||
def test_getbasetemp_custom_removes_old(self, testdir): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brief note (was stalking IRC so I saw this comment) --
resolve()
doesn't only resolve symlinks, but on windows it also resolves UNC paths from mounts (e.g. if you mount a network share atR:\\Some\\path
but it really points at\\10.1.100.100\Some\path
,Path.resolve()
captures that butos.path.abspath()
will returnR:\\blah
-- despiteabsolute
not being public we typically handle this by tryingresolve
and falling back onabsolute
in pipenv at leastThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @techalchemy for the note, that's interesting! 👍