Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


MS_WINDOWS = (os.name == 'nt')
MACOS = (sys.platform == 'darwin')

PYMEM_ALLOCATOR_NOT_SET = 0
PYMEM_ALLOCATOR_DEBUG = 2
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 11 additions & 1 deletion Programs/_testembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -1462,7 +1473,6 @@ static int test_init_setpath_config(void)
PyMem_RawFree(path);
putenv("TESTPATH=");

PyStatus status;
PyConfig config;

status = PyConfig_InitPythonConfig(&config);
Expand Down