Skip to content

Commit 173eaab

Browse files
authored
Fix test for Python >=3.13. (#2650)
The sysconfig module became a package in 3.13; so the test strategy for ammending getsitepackages was broken. Robustify with a sys.path common prefix match against the sysconfig module location.
1 parent c81fe25 commit 173eaab

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tests/test_pex.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from pex import resolver
1919
from pex.common import environment_as, safe_mkdir, safe_open, temporary_dir
20-
from pex.compatibility import PY2, WINDOWS, to_bytes
20+
from pex.compatibility import PY2, WINDOWS, commonpath, to_bytes
2121
from pex.dist_metadata import Distribution
2222
from pex.interpreter import PythonIdentity, PythonInterpreter
2323
from pex.pex import PEX, IsolatedSysPath
@@ -235,7 +235,14 @@ def test_site_libs_symlink(tmpdir):
235235
# bit of stdlib is on the sys.path. We get this by grabbing its sys.path entry, which contains
236236
# the whole stdlib in addition to it.
237237
assert sysconfig.__file__
238-
sys_path_entry = os.path.dirname(sysconfig.__file__)
238+
239+
sys_path_entries = tuple(
240+
entry
241+
for entry in PythonIdentity.get().sys_path
242+
if entry == commonpath((entry, sysconfig.__file__))
243+
)
244+
assert len(sys_path_entries) == 1
245+
sys_path_entry = sys_path_entries[0]
239246

240247
sys_path_entry_link = os.path.join(str(tmpdir), "lib-link")
241248
os.symlink(sys_path_entry, sys_path_entry_link)

0 commit comments

Comments
 (0)