nad0021 [Issue5408] test_osx_env fails in a non-framework build test_osx_env Could not find platform independent libraries Could not find platform dependent libraries Consider setting $PYTHONHOME to [:] Fatal Python error: Py_Initialize: can't initialize sys standard streams ImportError: No module named encodings.utf_8 test test_osx_env failed -- Traceback (most recent call last): File "/temp/python/py3k/Lib/test/test_osx_env.py", line 27, in test_pythonexecutable_sets_sys_executable self._check_sys('PYTHONEXECUTABLE', '==', 'sys.executable') File "/temp/python/py3k/Lib/test/test_osx_env.py", line 24, in _check_sys self.assertEqual(rc, 2, "expected %s %s %s" % (ev, cond, sv)) AssertionError: expected PYTHONEXECUTABLE == sys.executable ANALYSIS In a non-framework build, when PYTHONEXECUTABLE is set to a invalid value, getpath.c is unable to determine appropriate values for sys.prefix and sys.path so the interpreter fails in initialization. SOLUTION Simplify the test and supply appropriate values so the test works for both framework and non-framework builds. diff -r 5990b7fd9140 Lib/test/test_osx_env.py --- a/Lib/test/test_osx_env.py Mon Mar 02 20:28:59 2009 -0800 +++ b/Lib/test/test_osx_env.py Mon Mar 02 23:24:50 2009 -0800 @@ -8,7 +8,9 @@ import unittest class OSXEnvironmentVariableTestCase(unittest.TestCase): - def _check_sys(self, ev, cond, sv, val = '/some/path/to/python'): + def test_pythonexecutable_sets_sys_executable(self): + ev, cond, sv = 'PYTHONEXECUTABLE', '==', 'sys.executable' + val = '/some/path/to/python' with EnvironmentVarGuard() as evg: subpc = [str(sys.executable), '-c', 'import sys; sys.exit(2 if "%s" %s %s else 3)' % (val, cond, sv)] @@ -20,12 +22,13 @@ # set environ variable evg.set(ev, val) # test that sys.xxx has been influenced by the environ value + # but first ensure sys.path and sys.prefix have proper values + # (necessary for non-framework builds) + evg.set('PYTHONPATH', ':'.join(sys.path)) + evg.set('PYTHONHOME', sys.prefix) rc = subprocess.call(subpc) self.assertEqual(rc, 2, "expected %s %s %s" % (ev, cond, sv)) - def test_pythonexecutable_sets_sys_executable(self): - self._check_sys('PYTHONEXECUTABLE', '==', 'sys.executable') - def test_main(): if sys.platform == 'darwin': run_unittest(OSXEnvironmentVariableTestCase)