@@ -331,13 +331,22 @@ def test_cwd(self):
331331 def test_env (self ):
332332 newenv = os .environ .copy ()
333333 newenv ["FRUIT" ] = "orange"
334- p = subprocess .Popen ([sys .executable , "-c" ,
335- 'import sys,os;'
336- 'sys.stdout.write(os.getenv("FRUIT"))' ],
337- stdout = subprocess .PIPE ,
338- env = newenv )
339- self .addCleanup (p .stdout .close )
340- self .assertEqual (p .stdout .read (), b"orange" )
334+ with subprocess .Popen ([sys .executable , "-c" ,
335+ 'import sys,os;'
336+ 'sys.stdout.write(os.getenv("FRUIT"))' ],
337+ stdout = subprocess .PIPE ,
338+ env = newenv ) as p :
339+ stdout , stderr = p .communicate ()
340+ self .assertEqual (stdout , b"orange" )
341+
342+ def test_empty_env (self ):
343+ with subprocess .Popen ([sys .executable , "-c" ,
344+ 'import os; '
345+ 'print(len(os.environ))' ],
346+ stdout = subprocess .PIPE ,
347+ env = {}) as p :
348+ stdout , stderr = p .communicate ()
349+ self .assertEqual (stdout .strip (), b"0" )
341350
342351 def test_communicate_stdin (self ):
343352 p = subprocess .Popen ([sys .executable , "-c" ,
0 commit comments