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

Method test_one_environment_variable

Lib/test/test_subprocess.py:853–866  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

851 @unittest.skipIf(check_sanitizer(address=True),
852 'AddressSanitizer adds to the environment.')
853 def test_one_environment_variable(self):
854 newenv = {'fruit': 'orange'}
855 cmd = [sys.executable, '-c',
856 'import sys,os;'
857 'sys.stdout.write("fruit="+os.getenv("fruit"))']
858 if sys.platform == "win32":
859 cmd = ["CMD", "/c", "SET", "fruit"]
860 with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=newenv) as p:
861 stdout, stderr = p.communicate()
862 if p.returncode and support.verbose:
863 print("STDOUT:", stdout.decode("ascii", "replace"))
864 print("STDERR:", stderr.decode("ascii", "replace"))
865 self.assertEqual(p.returncode, 0)
866 self.assertEqual(stdout.strip(), b"fruit=orange")
867
868 def test_invalid_cmd(self):
869 # null character in the command name

Callers

nothing calls this directly

Calls 4

communicateMethod · 0.45
decodeMethod · 0.45
assertEqualMethod · 0.45
stripMethod · 0.45

Tested by

no test coverage detected