Mercurial > cpython-lru_cache-weakref
diff Lib/test/test_subprocess.py @ 70921:b5963fceddad 3.2
Close #12383: Fix subprocess module with env={}: don't copy the environment
variables, start with an empty environment.
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Tue, 21 Jun 2011 17:18:38 +0200 |
| parents | 22457ac2c2df |
| children | 8d46e84cd812 10ecf8576eb2 |
line wrap: on
line diff
--- a/Lib/test/test_subprocess.py Mon Jun 20 22:09:13 2011 -0500 +++ b/Lib/test/test_subprocess.py Tue Jun 21 17:18:38 2011 +0200 @@ -331,13 +331,22 @@ def test_env(self): newenv = os.environ.copy() newenv["FRUIT"] = "orange" - p = subprocess.Popen([sys.executable, "-c", - 'import sys,os;' - 'sys.stdout.write(os.getenv("FRUIT"))'], - stdout=subprocess.PIPE, - env=newenv) - self.addCleanup(p.stdout.close) - self.assertEqual(p.stdout.read(), b"orange") + with subprocess.Popen([sys.executable, "-c", + 'import sys,os;' + 'sys.stdout.write(os.getenv("FRUIT"))'], + stdout=subprocess.PIPE, + env=newenv) as p: + stdout, stderr = p.communicate() + self.assertEqual(stdout, b"orange") + + def test_empty_env(self): + with subprocess.Popen([sys.executable, "-c", + 'import os; ' + 'print(len(os.environ))'], + stdout=subprocess.PIPE, + env={}) as p: + stdout, stderr = p.communicate() + self.assertEqual(stdout.strip(), b"0") def test_communicate_stdin(self): p = subprocess.Popen([sys.executable, "-c",
