diff -r 92039fb68483 Lib/test/script_helper.py --- a/Lib/test/script_helper.py Thu Aug 15 11:57:19 2013 +0200 +++ b/Lib/test/script_helper.py Fri Aug 16 15:38:05 2013 +0200 @@ -17,8 +17,16 @@ from test.support import make_legacy_pyc # Executing the interpreter in a subprocess def _assert_python(expected_success, *args, **env_vars): + if 'python_isolated' in env_vars: + isolated = env_vars.pop('python_isolated') + else: + isolated = not env_vars cmd_line = [sys.executable, '-X', 'faulthandler'] - if not env_vars: + if isolated: + # isolated mode: ignore Python environment variables and ignore user + # site-packages, and don't add the current directory to sys.path + cmd_line.append('-I') + elif not env_vars: cmd_line.append('-E') # Need to preserve the original environment, for in-place testing of # shared library builds. @@ -51,6 +59,11 @@ def assert_python_ok(*args, **env_vars): Assert that running the interpreter with `args` and optional environment variables `env_vars` succeeds (rc == 0) and return a (return code, stdout, stderr) tuple. + + If the __cleanenv keyword is set, env_vars is used a fresh environment. + + Python is started in isolated mode (command line option -I), + except if the python_isolated keyword is set to False. """ return _assert_python(True, *args, **env_vars) @@ -59,6 +72,8 @@ def assert_python_failure(*args, **env_v Assert that running the interpreter with `args` and optional environment variables `env_vars` fails (rc != 0) and return a (return code, stdout, stderr) tuple. + + See assert_python_ok() to more options. """ return _assert_python(False, *args, **env_vars) diff -r 92039fb68483 Lib/test/test_cmd_line.py --- a/Lib/test/test_cmd_line.py Thu Aug 15 11:57:19 2013 +0200 +++ b/Lib/test/test_cmd_line.py Fri Aug 16 15:38:05 2013 +0200 @@ -263,7 +263,7 @@ class CmdLineTest(unittest.TestCase): path = path.encode("ascii", "backslashreplace") sys.stdout.buffer.write(path)""" rc1, out1, err1 = assert_python_ok('-c', code, PYTHONPATH="") - rc2, out2, err2 = assert_python_ok('-c', code) + rc2, out2, err2 = assert_python_ok('-c', code, python_isolated=False) # regarding to Posix specification, outputs should be equal # for empty and unset PYTHONPATH self.assertEqual(out1, out2) diff -r 92039fb68483 Lib/test/test_cmd_line_script.py --- a/Lib/test/test_cmd_line_script.py Thu Aug 15 11:57:19 2013 +0200 +++ b/Lib/test/test_cmd_line_script.py Fri Aug 16 15:38:05 2013 +0200 @@ -123,7 +123,7 @@ class CmdLineTest(unittest.TestCase): if not __debug__: cmd_line_switches += ('-' + 'O' * sys.flags.optimize,) run_args = cmd_line_switches + (script_name,) + tuple(example_args) - rc, out, err = assert_python_ok(*run_args) + rc, out, err = assert_python_ok(*run_args, python_isolated=False) self._check_output(script_name, rc, out + err, expected_file, expected_argv0, expected_path0, expected_package, expected_loader) @@ -294,7 +294,7 @@ class CmdLineTest(unittest.TestCase): pkg_dir = os.path.join(script_dir, 'test_pkg') make_pkg(pkg_dir, "import sys; print('init_argv0==%r' % sys.argv[0])") script_name = _make_test_script(pkg_dir, 'script') - rc, out, err = assert_python_ok('-m', 'test_pkg.script', *example_args) + rc, out, err = assert_python_ok('-m', 'test_pkg.script', *example_args, python_isolated=False) if verbose > 1: print(out) expected = "init_argv0==%r" % '-m' @@ -311,7 +311,8 @@ class CmdLineTest(unittest.TestCase): with open("-c", "w") as f: f.write("data") rc, out, err = assert_python_ok('-c', - 'import sys; print("sys.path[0]==%r" % sys.path[0])') + 'import sys; print("sys.path[0]==%r" % sys.path[0])', + python_isolated=False) if verbose > 1: print(out) expected = "sys.path[0]==%r" % '' @@ -325,7 +326,8 @@ class CmdLineTest(unittest.TestCase): with support.change_cwd(path=script_dir): with open("-m", "w") as f: f.write("data") - rc, out, err = assert_python_ok('-m', 'other', *example_args) + rc, out, err = assert_python_ok('-m', 'other', *example_args, + python_isolated=False) self._check_output(script_name, rc, out, script_name, script_name, '', '', importlib.machinery.SourceFileLoader) diff -r 92039fb68483 Lib/test/test_compileall.py --- a/Lib/test/test_compileall.py Thu Aug 15 11:57:19 2013 +0200 +++ b/Lib/test/test_compileall.py Fri Aug 16 15:38:05 2013 +0200 @@ -295,7 +295,7 @@ class CommandLineTests(unittest.TestCase pyc = importlib.util.cache_from_source(bazfn) os.rename(pyc, os.path.join(self.pkgdir, 'baz.pyc')) os.remove(bazfn) - rc, out, err = script_helper.assert_python_failure(fn) + rc, out, err = script_helper.assert_python_failure(fn, python_isolated=False) self.assertRegex(err, b'File "dinsdale') def test_include_bad_file(self):