From 9e55288ba498a3a7ba9a909b40e0b70a0c69f9b3 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Wed, 5 Aug 2020 18:36:41 +0300 Subject: [PATCH] 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. --- src/_pytest/pathlib.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index c3235f8b8..4a249c8fd 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -571,6 +571,15 @@ def visit( yield from visit(entry.path, recurse) +def absolutepath(path: Union[Path, 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))) + + def commonpath(path1: Path, path2: Path) -> Optional[Path]: """Return the common part shared with the other path, or None if there is no common part."""