@@ -1491,8 +1491,12 @@ def test_init_setpythonhome(self):
14911491 }
14921492 self .default_program_name (config )
14931493 env = {'TESTHOME' : home , 'PYTHONPATH' : paths_str }
1494+ # When running from source, TESTHOME will be the build directory, which
1495+ # isn't a valid home unless _is_python_build is set. getpath will then
1496+ # fail to find the standard library and show a warning, so we need to
1497+ # ignore stderr.
14941498 self .check_all_configs ("test_init_setpythonhome" , config ,
1495- api = API_COMPAT , env = env )
1499+ api = API_COMPAT , env = env , ignore_stderr = True )
14961500
14971501 def test_init_is_python_build_with_home (self ):
14981502 # Test _Py_path_config._is_python_build configuration (gh-91985)
@@ -1528,15 +1532,26 @@ def test_init_is_python_build_with_home(self):
15281532 'exec_prefix' : exec_prefix ,
15291533 'base_exec_prefix' : exec_prefix ,
15301534 'pythonpath_env' : paths_str ,
1531- 'stdlib_dir' : stdlib ,
1535+ 'stdlib_dir' : stdlib , # Only correct on _is_python_build==0!
15321536 }
15331537 # The code above is taken from test_init_setpythonhome()
15341538 env = {'TESTHOME' : home , 'PYTHONPATH' : paths_str }
15351539
15361540 env ['NEGATIVE_ISPYTHONBUILD' ] = '1'
15371541 config ['_is_python_build' ] = 0
1542+ # This configuration doesn't set a valid stdlibdir/plststdlibdir because
1543+ # with _is_python_build=0 getpath doesn't check for the build directory
1544+ # landmarks in PYTHONHOME/Py_SetPythonHome.
1545+ # getpath correctly shows a warning, which messes up check_all_configs,
1546+ # so we need to ignore stderr.
15381547 self .check_all_configs ("test_init_is_python_build" , config ,
1539- api = API_COMPAT , env = env )
1548+ api = API_COMPAT , env = env , ignore_stderr = True )
1549+
1550+ # config['stdlib_dir'] = os.path.join(home, 'Lib')
1551+ # FIXME: This test does not check if stdlib_dir is calculated correctly.
1552+ # test_init_is_python_build runs the initialization twice,
1553+ # setting stdlib_dir in _Py_path_config on the first run, which
1554+ # then overrides the stdlib_dir calculation (as of GH-108730).
15401555
15411556 env ['NEGATIVE_ISPYTHONBUILD' ] = '0'
15421557 config ['_is_python_build' ] = 1
@@ -1551,8 +1566,14 @@ def test_init_is_python_build_with_home(self):
15511566 expected_paths [0 ] = self .module_search_paths (prefix = prefix )[0 ]
15521567 config .update (prefix = prefix , base_prefix = prefix ,
15531568 exec_prefix = exec_prefix , base_exec_prefix = exec_prefix )
1569+ # This also shows the bad stdlib warning, getpath is run twice. The
1570+ # first time with _is_python_build=0, which results in the warning just
1571+ # as explained above. However, the second time a valid standard library
1572+ # should be found, but the stdlib_dir is cached in _Py_path_config from
1573+ # the first run, which ovewrites it, so it also shows the warning.
1574+ # Also ignore stderr.
15541575 self .check_all_configs ("test_init_is_python_build" , config ,
1555- api = API_COMPAT , env = env )
1576+ api = API_COMPAT , env = env , ignore_stderr = True )
15561577
15571578 def copy_paths_by_env (self , config ):
15581579 all_configs = self ._get_expected_config ()
@@ -1612,6 +1633,7 @@ def test_init_pybuilddir_win32(self):
16121633 prefix = os .path .normpath (os .path .join (tmpdir , vpath ))
16131634 # The stdlib dir is dirname(executable) + VPATH + 'Lib'
16141635 stdlibdir = os .path .normpath (os .path .join (tmpdir , vpath , 'Lib' ))
1636+ os .mkdir (stdlibdir )
16151637
16161638 filename = os .path .join (tmpdir , 'pybuilddir.txt' )
16171639 with open (filename , "w" , encoding = "utf8" ) as fp :
0 commit comments