Skip to content

Commit 9e55288

Browse files
committed
pathlib: add absolutepath() as alternative to Path.resolve()
Didn't call it absolute or absolute_path to avoid conflicts with possible variable names. Didn't call it abspath to avoid confusion with os.path.abspath.
1 parent e0d0951 commit 9e55288

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/_pytest/pathlib.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,15 @@ def visit(
571571
yield from visit(entry.path, recurse)
572572

573573

574+
def absolutepath(path: Union[Path, str]) -> Path:
575+
"""Convert a path to an absolute path using os.path.abspath.
576+
577+
Prefer this over Path.resolve() (see #6523).
578+
Prefer this over Path.absolute() (not public, doesn't normalize).
579+
"""
580+
return Path(os.path.abspath(str(path)))
581+
582+
574583
def commonpath(path1: Path, path2: Path) -> Optional[Path]:
575584
"""Return the common part shared with the other path, or None if there is
576585
no common part."""

0 commit comments

Comments
 (0)