diff --git a/pex/pex_info.py b/pex/pex_info.py index 9a8024326..47832531d 100644 --- a/pex/pex_info.py +++ b/pex/pex_info.py @@ -509,7 +509,7 @@ def pex_root(self): # type: () -> str pex_root = os.path.realpath(os.path.expanduser(self.raw_pex_root)) if not can_write_dir(pex_root): - tmp_root = safe_mkdtemp() + tmp_root = os.path.realpath(safe_mkdtemp()) pex_warnings.warn( "PEX_ROOT is configured as {pex_root} but that path is un-writeable, " "falling back to a temporary PEX_ROOT of {tmp_root} which will hurt " diff --git a/tests/test_variables.py b/tests/test_variables.py index 1d9a240bc..66abc7c8a 100644 --- a/tests/test_variables.py +++ b/tests/test_variables.py @@ -14,6 +14,7 @@ from pex.util import named_temporary_file from pex.variables import NoValueError, Variables from testing import environment_as +from testing.pytest.tmp import Tempdir if TYPE_CHECKING: from typing import Any @@ -196,27 +197,27 @@ def test_pex_vars_defaults_stripped(): assert Variables.PEX_VERBOSE.strip_default(v) is None -def test_pex_root_unwriteable(): - # type: () -> None - with temporary_dir() as td: - pex_root = os.path.realpath(os.path.join(td, "pex_root")) - os.mkdir(pex_root, 0o444) +def test_pex_root_unwriteable(tmpdir): + # type: (Tempdir) -> None + + pex_root = tmpdir.join("pex_root") + os.mkdir(pex_root, 0o444) - env = Variables(environ=dict(PEX_ROOT=pex_root)) + env = Variables(environ=dict(PEX_ROOT=pex_root)) - with warnings.catch_warnings(record=True) as log: - assert pex_root != env.PEX_ROOT + with warnings.catch_warnings(record=True) as log: + assert pex_root != env.PEX_ROOT - assert 1 == len(log) - message = log[0].message - assert isinstance(message, PEXWarning) - assert pex_root in str(message) - assert env.PEX_ROOT is not None - assert env.PEX_ROOT in str(message) + assert 1 == len(log) + message = log[0].message + assert isinstance(message, PEXWarning) + assert pex_root in str(message) + assert env.PEX_ROOT is not None + assert env.PEX_ROOT in str(message) - assert ( - env.PEX_ROOT == env.PEX_ROOT - ), "When an ephemeral PEX_ROOT is materialized it should be stable." + assert ( + env.PEX_ROOT == env.PEX_ROOT + ), "When an ephemeral PEX_ROOT is materialized it should be stable." def test_pex_vars_value_or(tmpdir):