summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2018-02-18 04:35:03 (GMT)
committerGitHub <noreply@github.com>2018-02-18 04:35:03 (GMT)
commit17ca4e193ea25f13a5f0309a0713a6b5bedaf3e4 (patch)
treee0a170216b4c3fd75d942e61ffc0187a92322a6b /Lib
parentc1b8aedfbabf6e5460b09f4792d80f18051d43d3 (diff)
downloadcpython-17ca4e193ea25f13a5f0309a0713a6b5bedaf3e4.zip
cpython-17ca4e193ea25f13a5f0309a0713a6b5bedaf3e4.tar.gz
cpython-17ca4e193ea25f13a5f0309a0713a6b5bedaf3e4.tar.bz2
[3.6] Improves the ability to build in CI (GH-5730)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/support/script_helper.py9
-rw-r--r--Lib/test/test_cmd_line.py11
2 files changed, 13 insertions, 7 deletions
diff --git a/Lib/test/support/script_helper.py b/Lib/test/support/script_helper.py
index ca5f9c20..507dc48 100644
--- a/Lib/test/support/script_helper.py
+++ b/Lib/test/support/script_helper.py
@@ -39,6 +39,11 @@ def interpreter_requires_environment():
"""
global __cached_interp_requires_environment
if __cached_interp_requires_environment is None:
+ # If PYTHONHOME is set, assume that we need it
+ if 'PYTHONHOME' in os.environ:
+ __cached_interp_requires_environment = True
+ return True
+
# Try running an interpreter with -E to see if it works or not.
try:
subprocess.check_call([sys.executable, '-E',
@@ -165,7 +170,9 @@ def spawn_python(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
kw is extra keyword args to pass to subprocess.Popen. Returns a Popen
object.
"""
- cmd_line = [sys.executable, '-E']
+ cmd_line = [sys.executable]
+ if not interpreter_requires_environment():
+ cmd_line.append('-E')
cmd_line.extend(args)
# Under Fedora (?), GNU readline can output junk on stderr when initialized,
# depending on the TERM setting. Setting TERM=vt100 is supposed to disable
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 98441b0..32d2df9 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -10,7 +10,7 @@ import subprocess
import tempfile
from test.support import script_helper, is_android
from test.support.script_helper import (spawn_python, kill_python, assert_python_ok,
- assert_python_failure)
+ assert_python_failure, interpreter_requires_environment)
# XXX (ncoghlan): Move to script_helper and make consistent with run_python
@@ -57,6 +57,8 @@ class CmdLineTest(unittest.TestCase):
rc, out, err = assert_python_ok('-vv')
self.assertNotIn(b'stack overflow', err)
+ @unittest.skipIf(interpreter_requires_environment(),
+ 'Cannot run -E tests when PYTHON env vars are required.')
def test_xoptions(self):
def get_xoptions(*args):
# use subprocess module directly because test.support.script_helper adds
@@ -272,11 +274,7 @@ class CmdLineTest(unittest.TestCase):
def test_displayhook_unencodable(self):
for encoding in ('ascii', 'latin-1', 'utf-8'):
- # We are testing a PYTHON environment variable here, so we can't
- # use -E, -I, or script_helper (which uses them). So instead we do
- # poor-man's isolation by deleting the PYTHON vars from env.
- env = {key:value for (key,value) in os.environ.copy().items()
- if not key.startswith('PYTHON')}
+ env = os.environ.copy()
env['PYTHONIOENCODING'] = encoding
p = subprocess.Popen(
[sys.executable, '-i'],
@@ -491,6 +489,7 @@ class CmdLineTest(unittest.TestCase):
cwd=tmpdir)
self.assertEqual(out.strip(), b"ok")
+
def test_main():
test.support.run_unittest(CmdLineTest)
test.support.reap_children()