From 80ca255d424da35f8a28216dc25170850779ff93 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 27 Apr 2024 11:03:52 +0300 Subject: [PATCH] pathlib: make `absolutepath` support `os.PathLike[str]` This slightly simplifies a bit of path. --- src/_pytest/nodes.py | 2 +- src/_pytest/pathlib.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index 1b91bdb6e..974d756a2 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -765,7 +765,7 @@ class Item(Node, abc.ABC): and lineno is a 0-based line number. """ location = self.reportinfo() - path = absolutepath(os.fspath(location[0])) + path = absolutepath(location[0]) relfspath = self.session._node_location_to_relpath(path) assert type(location[2]) is str return (relfspath, location[1], location[2]) diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index 190d9dd8c..e14c2acd3 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -924,13 +924,13 @@ def visit( yield from visit(entry.path, recurse) -def absolutepath(path: Union[Path, str]) -> Path: +def absolutepath(path: "Union[str, os.PathLike[str]]") -> Path: """Convert a path to an absolute path using os.path.abspath. Prefer this over Path.resolve() (see #6523). Prefer this over Path.absolute() (not public, doesn't normalize). """ - return Path(os.path.abspath(str(path))) + return Path(os.path.abspath(path)) def commonpath(path1: Path, path2: Path) -> Optional[Path]: