Skip to content

Commit 80ca255

Browse files
committed
pathlib: make absolutepath support os.PathLike[str]
This slightly simplifies a bit of path.
1 parent 1a33280 commit 80ca255

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/_pytest/nodes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ def location(self) -> Tuple[str, Optional[int], str]:
765765
and lineno is a 0-based line number.
766766
"""
767767
location = self.reportinfo()
768-
path = absolutepath(os.fspath(location[0]))
768+
path = absolutepath(location[0])
769769
relfspath = self.session._node_location_to_relpath(path)
770770
assert type(location[2]) is str
771771
return (relfspath, location[1], location[2])

src/_pytest/pathlib.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -924,13 +924,13 @@ def visit(
924924
yield from visit(entry.path, recurse)
925925

926926

927-
def absolutepath(path: Union[Path, str]) -> Path:
927+
def absolutepath(path: "Union[str, os.PathLike[str]]") -> Path:
928928
"""Convert a path to an absolute path using os.path.abspath.
929929
930930
Prefer this over Path.resolve() (see #6523).
931931
Prefer this over Path.absolute() (not public, doesn't normalize).
932932
"""
933-
return Path(os.path.abspath(str(path)))
933+
return Path(os.path.abspath(path))
934934

935935

936936
def commonpath(path1: Path, path2: Path) -> Optional[Path]:

0 commit comments

Comments
 (0)