summaryrefslogtreecommitdiff
path: root/Lib/test/test_cmd_line.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-11-30 11:40:24 +0100
committerGitHub <noreply@github.com>2017-11-30 11:40:24 +0100
commit5e3806f8cfd84722fc55d4299dc018ad9b0f8401 (patch)
tree436f0a963001f590a1193dba5c84627ba59513c2 /Lib/test/test_cmd_line.py
parent706e10b186992e086e661a62d2c8ec9588525b31 (diff)
downloadcpython-git-5e3806f8cfd84722fc55d4299dc018ad9b0f8401.tar.gz
bpo-32101: Add PYTHONDEVMODE environment variable (#4624)
* bpo-32101: Add sys.flags.dev_mode flag Rename also the "Developer mode" to the "Development mode". * bpo-32101: Add PYTHONDEVMODE environment variable Mention it in the development chapiter.
Diffstat (limited to 'Lib/test/test_cmd_line.py')
-rw-r--r--Lib/test/test_cmd_line.py37
1 files changed, 35 insertions, 2 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 96405e70af..383302bad8 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -508,14 +508,18 @@ class CmdLineTest(unittest.TestCase):
with self.subTest(envar_value=value):
assert_python_ok('-c', code, **env_vars)
- def run_xdev(self, *args, check_exitcode=True):
+ def run_xdev(self, *args, check_exitcode=True, xdev=True):
env = dict(os.environ)
env.pop('PYTHONWARNINGS', None)
+ env.pop('PYTHONDEVMODE', None)
# Force malloc() to disable the debug hooks which are enabled
# by default for Python compiled in debug mode
env['PYTHONMALLOC'] = 'malloc'
- args = (sys.executable, '-X', 'dev', *args)
+ if xdev:
+ args = (sys.executable, '-X', 'dev', *args)
+ else:
+ args = (sys.executable, *args)
proc = subprocess.run(args,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
@@ -526,6 +530,14 @@ class CmdLineTest(unittest.TestCase):
return proc.stdout.rstrip()
def test_xdev(self):
+ # sys.flags.dev_mode
+ code = "import sys; print(sys.flags.dev_mode)"
+ out = self.run_xdev("-c", code, xdev=False)
+ self.assertEqual(out, "False")
+ out = self.run_xdev("-c", code)
+ self.assertEqual(out, "True")
+
+ # Warnings
code = ("import sys, warnings; "
"print(' '.join('%s::%s' % (f[0], f[2].__name__) "
"for f in warnings.filters))")
@@ -555,6 +567,7 @@ class CmdLineTest(unittest.TestCase):
"default::ResourceWarning "
"default::Warning")
+ # Memory allocator debug hooks
try:
import _testcapi
except ImportError:
@@ -569,6 +582,7 @@ class CmdLineTest(unittest.TestCase):
alloc_name = "malloc_debug"
self.assertEqual(out, alloc_name)
+ # Faulthandler
try:
import faulthandler
except ImportError:
@@ -581,6 +595,7 @@ class CmdLineTest(unittest.TestCase):
def check_pythonmalloc(self, env_var, name):
code = 'import _testcapi; print(_testcapi.pymem_getallocatorsname())'
env = dict(os.environ)
+ env.pop('PYTHONDEVMODE', None)
if env_var is not None:
env['PYTHONMALLOC'] = env_var
else:
@@ -621,6 +636,24 @@ class CmdLineTest(unittest.TestCase):
with self.subTest(env_var=env_var, name=name):
self.check_pythonmalloc(env_var, name)
+ def test_pythondevmode_env(self):
+ # Test the PYTHONDEVMODE environment variable
+ code = "import sys; print(sys.flags.dev_mode)"
+ env = dict(os.environ)
+ env.pop('PYTHONDEVMODE', None)
+ args = (sys.executable, '-c', code)
+
+ proc = subprocess.run(args, stdout=subprocess.PIPE,
+ universal_newlines=True, env=env)
+ self.assertEqual(proc.stdout.rstrip(), 'False')
+ self.assertEqual(proc.returncode, 0, proc)
+
+ env['PYTHONDEVMODE'] = '1'
+ proc = subprocess.run(args, stdout=subprocess.PIPE,
+ universal_newlines=True, env=env)
+ self.assertEqual(proc.stdout.rstrip(), 'True')
+ self.assertEqual(proc.returncode, 0, proc)
+
class IgnoreEnvironmentTest(unittest.TestCase):