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').
This commit is contained in:
Victor Stinner 2019-09-26 04:01:49 +02:00 committed by GitHub
parent 88feaecd46
commit 49d99f01e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 8 deletions

View File

@ -15,6 +15,7 @@ import textwrap
MS_WINDOWS = (os.name == 'nt') MS_WINDOWS = (os.name == 'nt')
MACOS = (sys.platform == 'darwin')
PYMEM_ALLOCATOR_NOT_SET = 0 PYMEM_ALLOCATOR_NOT_SET = 0
PYMEM_ALLOCATOR_DEBUG = 2 PYMEM_ALLOCATOR_DEBUG = 2
@ -1011,6 +1012,9 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
executable = self.test_exe executable = self.test_exe
else: else:
program_name = 'python3' program_name = 'python3'
if MACOS:
executable = self.test_exe
else:
executable = shutil.which(program_name) or '' executable = shutil.which(program_name) or ''
config.update({ config.update({
'program_name': program_name, 'program_name': program_name,
@ -1054,13 +1058,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'executable': 'conf_executable', 'executable': 'conf_executable',
} }
env = {'TESTPATH': os.path.pathsep.join(paths)} 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, self.check_all_configs("test_init_setpath_config", config,
api=API_PYTHON, api=API_PYTHON, env=env, ignore_stderr=True)
preconfig_api=API_COMPAT,
env=env,
ignore_stderr=True)
def module_search_paths(self, prefix=None, exec_prefix=None): def module_search_paths(self, prefix=None, exec_prefix=None):
config = self._get_expected_config() config = self._get_expected_config()

View File

@ -1448,6 +1448,17 @@ static int test_init_setpath(void)
static int test_init_setpath_config(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"); char *env = getenv("TESTPATH");
if (!env) { if (!env) {
fprintf(stderr, "missing TESTPATH env var\n"); fprintf(stderr, "missing TESTPATH env var\n");
@ -1462,7 +1473,6 @@ static int test_init_setpath_config(void)
PyMem_RawFree(path); PyMem_RawFree(path);
putenv("TESTPATH="); putenv("TESTPATH=");
PyStatus status;
PyConfig config; PyConfig config;
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);