From 67576f56f5f3f4851aeccc271cf4b564b9015014 Mon Sep 17 00:00:00 2001 From: Artem Mukhin Date: Tue, 4 Apr 2023 11:40:42 +0200 Subject: [PATCH 1/2] GH-103224: Use the realpath of the Python executable in `test_venv` Now running tests through a Python symlink no longer causes `test_upgrade_dependencies` and `test_zippath_from_non_installed_posix` to fail. --- Lib/test/test_venv.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 4e18dfc23c40c2..3aff983763401f 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -208,7 +208,8 @@ def test_prompt(self): def test_upgrade_dependencies(self): builder = venv.EnvBuilder() bin_path = 'Scripts' if sys.platform == 'win32' else 'bin' - python_exe = os.path.split(sys.executable)[1] + python_exe_realpath = os.path.realpath(sys.executable) + python_exe = os.path.split(python_exe_realpath)[1] with tempfile.TemporaryDirectory() as fake_env_dir: expect_exe = os.path.normcase( os.path.join(fake_env_dir, bin_path, python_exe) @@ -552,7 +553,8 @@ def test_zippath_from_non_installed_posix(self): self.addCleanup(rmtree, non_installed_dir) bindir = os.path.join(non_installed_dir, self.bindir) os.mkdir(bindir) - shutil.copy2(sys.executable, bindir) + python_exe_realpath = os.path.realpath(sys.executable) + shutil.copy2(python_exe_realpath, bindir) libdir = os.path.join(non_installed_dir, platlibdir, self.lib[1]) os.makedirs(libdir) landmark = os.path.join(libdir, "os.py") @@ -596,7 +598,7 @@ def test_zippath_from_non_installed_posix(self): # libpython.so ld_library_path = sysconfig.get_config_var("LIBDIR") if not ld_library_path or sysconfig.is_python_build(): - ld_library_path = os.path.abspath(os.path.dirname(sys.executable)) + ld_library_path = os.path.abspath(os.path.dirname(python_exe_realpath)) if sys.platform == 'darwin': ld_library_path_env = "DYLD_LIBRARY_PATH" else: From b75f8812b0be39274b3f8328f4913f3884c38c55 Mon Sep 17 00:00:00 2001 From: Artem Mukhin Date: Wed, 12 Apr 2023 12:56:03 +0200 Subject: [PATCH 2/2] Use `sys._base_executable` instead of `sys.executable` in `test_venv` --- Lib/test/test_venv.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 3aff983763401f..5035705332c383 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -208,7 +208,7 @@ def test_prompt(self): def test_upgrade_dependencies(self): builder = venv.EnvBuilder() bin_path = 'Scripts' if sys.platform == 'win32' else 'bin' - python_exe_realpath = os.path.realpath(sys.executable) + python_exe_realpath = os.path.realpath(sys._base_executable) python_exe = os.path.split(python_exe_realpath)[1] with tempfile.TemporaryDirectory() as fake_env_dir: expect_exe = os.path.normcase( @@ -553,7 +553,7 @@ def test_zippath_from_non_installed_posix(self): self.addCleanup(rmtree, non_installed_dir) bindir = os.path.join(non_installed_dir, self.bindir) os.mkdir(bindir) - python_exe_realpath = os.path.realpath(sys.executable) + python_exe_realpath = os.path.realpath(sys._base_executable) shutil.copy2(python_exe_realpath, bindir) libdir = os.path.join(non_installed_dir, platlibdir, self.lib[1]) os.makedirs(libdir)