diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-06-21 15:18:38 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-06-21 15:18:38 (GMT) |
commit | f1512a2967ac30c38135fb950d623d5fed856494 (patch) | |
tree | 03aaf88b18adecd7e97b29d89cd7f659d1264848 /Lib/test | |
parent | b7149cad045b0273e2cb104a1f15ff942eab1cf6 (diff) | |
download | cpython-f1512a2967ac30c38135fb950d623d5fed856494.zip cpython-f1512a2967ac30c38135fb950d623d5fed856494.tar.gz cpython-f1512a2967ac30c38135fb950d623d5fed856494.tar.bz2 |
Close #12383: Fix subprocess module with env={}: don't copy the environment
variables, start with an empty environment.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_subprocess.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index e6e8b3a..3ee2e6e 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -331,13 +331,22 @@ class ProcessTestCase(BaseTestCase): 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", |