diff --git a/src/molecule/util.py b/src/molecule/util.py index dbd934da74..a57abc61ea 100644 --- a/src/molecule/util.py +++ b/src/molecule/util.py @@ -402,7 +402,7 @@ def abs_path(path: str | Path | None) -> str | Path: """Return absolute path. Args: - path: File path to resolve absolute path from. + path: File path to create absolute path from. Returns: Absolute path of path. @@ -411,9 +411,9 @@ def abs_path(path: str | Path | None) -> str | Path: return "" output_type = type(path) - if isinstance(path, str): - path = Path(path) - path = path.resolve() + if isinstance(path, Path): + path = str(path) + path = os.path.abspath(path) # noqa: PTH100 return output_type(path) diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py index 095e10dbf9..0b94bd5207 100644 --- a/tests/unit/test_util.py +++ b/tests/unit/test_util.py @@ -21,6 +21,7 @@ import binascii import os +import tempfile import warnings from pathlib import Path @@ -340,6 +341,17 @@ def test_abs_path_with_empty_path() -> None: assert util.abs_path("") == "" +def test_abs_path_with_symlink() -> None: + """Test the `abs_path` function not resolving symlinks.""" + with tempfile.NamedTemporaryFile() as tmp_file: + tmpfile_path = Path(tmp_file.name) + symlink_path = Path(tmp_file.name + "_sym") + symlink_path.symlink_to(tmpfile_path) + abs_path_result = util.abs_path(symlink_path) + symlink_path.unlink() + assert abs_path_result == symlink_path + + @pytest.mark.parametrize( ("a", "b", "x"), [ # noqa: PT007