summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cmd_line.py
diff options
context:
space:
mode:
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 96405e7..383302b 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):