MCPcopy Index your code
hub / github.com/python/cpython / test_empty_env

Method test_empty_env

Lib/test/test_subprocess.py:826–846  ·  view source on GitHub ↗

Verify that env={} is as empty as possible.

(self)

Source from the content-addressed store, hash-verified

824 @unittest.skipIf(check_sanitizer(address=True),
825 'AddressSanitizer adds to the environment.')
826 def test_empty_env(self):
827 """Verify that env={} is as empty as possible."""
828
829 def is_env_var_to_ignore(n):
830 """Determine if an environment variable is under our control."""
831 # This excludes some __CF_* and VERSIONER_* keys MacOS insists
832 # on adding even when the environment in exec is empty.
833 # Gentoo sandboxes also force LD_PRELOAD and SANDBOX_* to exist.
834 return ('VERSIONER' in n or '__CF' in n or # MacOS
835 n == 'LD_PRELOAD' or n.startswith('SANDBOX') or # Gentoo
836 n == 'LC_CTYPE') # Locale coercion triggered
837
838 with subprocess.Popen([sys.executable, "-c",
839 'import os; print(list(os.environ.keys()))'],
840 stdout=subprocess.PIPE, env={}) as p:
841 stdout, stderr = p.communicate()
842 child_env_names = eval(stdout.strip())
843 self.assertIsInstance(child_env_names, list)
844 child_env_names = [k for k in child_env_names
845 if not is_env_var_to_ignore(k)]
846 self.assertEqual(child_env_names, [])
847
848 @unittest.skipIf(sysconfig.get_config_var('Py_ENABLE_SHARED') == 1,
849 'The Python shared library cannot be loaded '

Callers

nothing calls this directly

Calls 4

assertIsInstanceMethod · 0.80
communicateMethod · 0.45
stripMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected