summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-06-21 15:24:21 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-06-21 15:24:21 (GMT)
commit372b838db50540587f643bf553dc070589fe500b (patch)
treee7eabc07d1c52ffed62001ad85b70e598b3b52e8 /Lib/test
parent28db0fd3575ebe5f155d4e04fcfaebc33957ae28 (diff)
parentf1512a2967ac30c38135fb950d623d5fed856494 (diff)
downloadcpython-372b838db50540587f643bf553dc070589fe500b.zip
cpython-372b838db50540587f643bf553dc070589fe500b.tar.gz
cpython-372b838db50540587f643bf553dc070589fe500b.tar.bz2
(merge 3.2) 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.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index b52d8e8..b871359 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -382,13 +382,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",