Suppress a possible relative_to() failure, fixes #9894
This commit is contained in:
parent
a88c0f3bb0
commit
444e54deed
1
AUTHORS
1
AUTHORS
|
@ -312,6 +312,7 @@ Stefan Scherfke
|
||||||
Stefan Zimmermann
|
Stefan Zimmermann
|
||||||
Stefano Taschini
|
Stefano Taschini
|
||||||
Steffen Allner
|
Steffen Allner
|
||||||
|
Stephan Loyd
|
||||||
Stephan Obermann
|
Stephan Obermann
|
||||||
Sven-Hendrik Haase
|
Sven-Hendrik Haase
|
||||||
Sylvain Marié
|
Sylvain Marié
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Suppress a potential pathlib relative_to() error, which is possible to be raised from ExceptionInfo.getexpr() when running Python from double-slashed path (like //usr/bin/python3) and single-slashed tests path.
|
|
@ -707,8 +707,12 @@ def bestrelpath(directory: Path, dest: Path) -> str:
|
||||||
# Can be the case for a relative path and an absolute path.
|
# Can be the case for a relative path and an absolute path.
|
||||||
if not base:
|
if not base:
|
||||||
return str(dest)
|
return str(dest)
|
||||||
|
try:
|
||||||
reldirectory = directory.relative_to(base)
|
reldirectory = directory.relative_to(base)
|
||||||
reldest = dest.relative_to(base)
|
reldest = dest.relative_to(base)
|
||||||
|
except ValueError:
|
||||||
|
# GH 9894
|
||||||
|
return str(dest)
|
||||||
return os.path.join(
|
return os.path.join(
|
||||||
# Back from directory to base.
|
# Back from directory to base.
|
||||||
*([os.pardir] * len(reldirectory.parts)),
|
*([os.pardir] * len(reldirectory.parts)),
|
||||||
|
|
|
@ -413,6 +413,11 @@ def test_bestrelpath() -> None:
|
||||||
assert bestrelpath(curdir, curdir.parent) == ".."
|
assert bestrelpath(curdir, curdir.parent) == ".."
|
||||||
assert bestrelpath(curdir, Path("hello")) == "hello"
|
assert bestrelpath(curdir, Path("hello")) == "hello"
|
||||||
|
|
||||||
|
# GH 9894
|
||||||
|
directory = Path("/var/tmp/pytest-issue")
|
||||||
|
dest = Path("//usr/lib/python3.9/importlib/__init__.py")
|
||||||
|
assert bestrelpath(directory, dest) == str(dest)
|
||||||
|
|
||||||
|
|
||||||
def test_commonpath() -> None:
|
def test_commonpath() -> None:
|
||||||
path = Path("/foo/bar/baz/path")
|
path = Path("/foo/bar/baz/path")
|
||||||
|
|
Loading…
Reference in New Issue