[Python-checkins] bpo-38234: Fix test_embed.test_init_setpath_config() on FreeBSD (GH-16406)

Victor Stinner webhook-mailer at python.org
Wed Sep 25 22:01:54 EDT 2019


https://github.com/python/cpython/commit/49d99f01e6e51acec5ca57a02e857f0796bc418b
commit: 49d99f01e6e51acec5ca57a02e857f0796bc418b
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2019-09-26T04:01:49+02:00
summary:

bpo-38234: Fix test_embed.test_init_setpath_config() on FreeBSD (GH-16406)

Explicitly preinitializes with a Python preconfiguration to avoid
Py_SetPath() implicit preinitialization with a compat
preconfiguration.

Fix also test_init_setpath() and test_init_setpythonhome() on macOS:
use self.test_exe as the executable (and base_executable), rather
than shutil.which('python3').

files:
M Lib/test/test_embed.py
M Programs/_testembed.c

diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 8855e907c253..92b5136db7ea 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -15,6 +15,7 @@
 
 
 MS_WINDOWS = (os.name == 'nt')
+MACOS = (sys.platform == 'darwin')
 
 PYMEM_ALLOCATOR_NOT_SET = 0
 PYMEM_ALLOCATOR_DEBUG = 2
@@ -1011,7 +1012,10 @@ def default_program_name(self, config):
             executable = self.test_exe
         else:
             program_name = 'python3'
-            executable = shutil.which(program_name) or ''
+            if MACOS:
+                executable = self.test_exe
+            else:
+                executable = shutil.which(program_name) or ''
         config.update({
             'program_name': program_name,
             'base_executable': executable,
@@ -1054,13 +1058,8 @@ def test_init_setpath_config(self):
             'executable': 'conf_executable',
         }
         env = {'TESTPATH': os.path.pathsep.join(paths)}
-        # Py_SetPath() preinitialized Python using the compat API,
-        # so we need preconfig_api=API_COMPAT.
         self.check_all_configs("test_init_setpath_config", config,
-                               api=API_PYTHON,
-                               preconfig_api=API_COMPAT,
-                               env=env,
-                               ignore_stderr=True)
+                               api=API_PYTHON, env=env, ignore_stderr=True)
 
     def module_search_paths(self, prefix=None, exec_prefix=None):
         config = self._get_expected_config()
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index 14fca24f318f..83c266b885af 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -1448,6 +1448,17 @@ static int test_init_setpath(void)
 
 static int test_init_setpath_config(void)
 {
+    PyStatus status;
+    PyPreConfig preconfig;
+    PyPreConfig_InitPythonConfig(&preconfig);
+
+    /* Explicitly preinitializes with Python preconfiguration to avoid
+      Py_SetPath() implicit preinitialization with compat preconfiguration. */
+    status = Py_PreInitialize(&preconfig);
+    if (PyStatus_Exception(status)) {
+        Py_ExitStatusException(status);
+    }
+
     char *env = getenv("TESTPATH");
     if (!env) {
         fprintf(stderr, "missing TESTPATH env var\n");
@@ -1462,7 +1473,6 @@ static int test_init_setpath_config(void)
     PyMem_RawFree(path);
     putenv("TESTPATH=");
 
-    PyStatus status;
     PyConfig config;
 
     status = PyConfig_InitPythonConfig(&config);



More information about the Python-checkins mailing list