[Python-checkins] cpython (merge 3.4 -> default): Only pass -E to the child interpreter if our interpreter was running in that

gregory.p.smith python-checkins at python.org
Fri Jan 23 02:54:15 CET 2015


https://hg.python.org/cpython/rev/94cade7f6e21
changeset:   94248:94cade7f6e21
parent:      94246:5dc7df4e4143
parent:      94247:7f3ac2ce24ed
user:        Gregory P. Smith <greg at krypto.org>
date:        Thu Jan 22 17:53:24 2015 -0800
summary:
  Only pass -E to the child interpreter if our interpreter was running in that
mode.  Explicitly remove the PYTHONFAULTHANDLER environment variable before
launching a child interpreter when its presence would impact the test (the
reason -E was being used in the first place).

This enables running the test in an environment where other Python environment  variables must be set in order for things to run (such as using PYTHONHOME to
tell an embedded interpreter where it should think it lives).

files:
  Lib/test/test_faulthandler.py |  22 +++++++++++++++-------
  1 files changed, 15 insertions(+), 7 deletions(-)


diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py
--- a/Lib/test/test_faulthandler.py
+++ b/Lib/test/test_faulthandler.py
@@ -260,17 +260,25 @@
     def test_disabled_by_default(self):
         # By default, the module should be disabled
         code = "import faulthandler; print(faulthandler.is_enabled())"
-        args = (sys.executable, '-E', '-c', code)
-        # don't use assert_python_ok() because it always enable faulthandler
-        output = subprocess.check_output(args)
+        args = filter(None, (sys.executable,
+                             "-E" if sys.flags.ignore_environment else "",
+                             "-c", code))
+        env = os.environ.copy()
+        env.pop("PYTHONFAULTHANDLER", None)
+        # don't use assert_python_ok() because it always enables faulthandler
+        output = subprocess.check_output(args, env=env)
         self.assertEqual(output.rstrip(), b"False")
 
     def test_sys_xoptions(self):
         # Test python -X faulthandler
         code = "import faulthandler; print(faulthandler.is_enabled())"
-        args = (sys.executable, "-E", "-X", "faulthandler", "-c", code)
-        # don't use assert_python_ok() because it always enable faulthandler
-        output = subprocess.check_output(args)
+        args = filter(None, (sys.executable,
+                             "-E" if sys.flags.ignore_environment else "",
+                             "-X", "faulthandler", "-c", code))
+        env = os.environ.copy()
+        env.pop("PYTHONFAULTHANDLER", None)
+        # don't use assert_python_ok() because it always enables faulthandler
+        output = subprocess.check_output(args, env=env)
         self.assertEqual(output.rstrip(), b"True")
 
     def test_env_var(self):
@@ -279,7 +287,7 @@
         args = (sys.executable, "-c", code)
         env = os.environ.copy()
         env['PYTHONFAULTHANDLER'] = ''
-        # don't use assert_python_ok() because it always enable faulthandler
+        # don't use assert_python_ok() because it always enables faulthandler
         output = subprocess.check_output(args, env=env)
         self.assertEqual(output.rstrip(), b"False")
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list