Skip to content

Commit 36e43a7

Browse files
committed
Fix test_init_is_python_build_with_home
Signed-off-by: Filipe Laíns <lains@riseup.net>
1 parent d8b5280 commit 36e43a7

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

Lib/test/test_embed.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,15 +1528,26 @@ def test_init_is_python_build_with_home(self):
15281528
'exec_prefix': exec_prefix,
15291529
'base_exec_prefix': exec_prefix,
15301530
'pythonpath_env': paths_str,
1531-
'stdlib_dir': stdlib,
1531+
'stdlib_dir': stdlib, # Only correct on _is_python_build==0!
15321532
}
15331533
# The code above is taken from test_init_setpythonhome()
15341534
env = {'TESTHOME': home, 'PYTHONPATH': paths_str}
15351535

15361536
env['NEGATIVE_ISPYTHONBUILD'] = '1'
15371537
config['_is_python_build'] = 0
1538+
# This configuration doesn't set a valid stdlibdir/plststdlibdir because
1539+
# with _is_python_build=0 getpath doesn't check for the build directory
1540+
# landmarks in PYTHONHOME/Py_SetPythonHome.
1541+
# getpath correctly shows a warning, which messes up check_all_configs,
1542+
# so we need to ignore stderr.
15381543
self.check_all_configs("test_init_is_python_build", config,
1539-
api=API_COMPAT, env=env)
1544+
api=API_COMPAT, env=env, ignore_stderr=True)
1545+
1546+
# config['stdlib_dir'] = os.path.join(home, 'Lib')
1547+
# FIXME: This test does not check if stdlib_dir is calculated correctly.
1548+
# test_init_is_python_build runs the initialization twice,
1549+
# setting stdlib_dir in _Py_path_config on the first run, which
1550+
# then overrides the stdlib_dir calculation (as of GH-108730).
15401551

15411552
env['NEGATIVE_ISPYTHONBUILD'] = '0'
15421553
config['_is_python_build'] = 1
@@ -1551,8 +1562,14 @@ def test_init_is_python_build_with_home(self):
15511562
expected_paths[0] = self.module_search_paths(prefix=prefix)[0]
15521563
config.update(prefix=prefix, base_prefix=prefix,
15531564
exec_prefix=exec_prefix, base_exec_prefix=exec_prefix)
1565+
# This also shows the bad stdlib warning, getpath is run twice. The
1566+
# first time with _is_python_build=0, which results in the warning just
1567+
# as explained above. However, the second time a valid standard library
1568+
# should be found, but the stdlib_dir is cached in _Py_path_config from
1569+
# the first run, which ovewrites it, so it also shows the warning.
1570+
# Also ignore stderr.
15541571
self.check_all_configs("test_init_is_python_build", config,
1555-
api=API_COMPAT, env=env)
1572+
api=API_COMPAT, env=env, ignore_stderr=True)
15561573

15571574
def copy_paths_by_env(self, config):
15581575
all_configs = self._get_expected_config()

0 commit comments

Comments
 (0)