Index: Lib/test/test_os.py =================================================================== --- Lib/test/test_os.py (revision 85983) +++ Lib/test/test_os.py (working copy) @@ -406,8 +406,9 @@ os.environ.clear() if os.path.exists("/bin/sh"): os.environ.update(HELLO="World") - value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip() - self.assertEquals(value, "World") + with os.popen("/bin/sh -c 'echo $HELLO'") as popen: + value = popen.read().strip() + self.assertEquals(value, "World") def test_os_popen_iter(self): if os.path.exists("/bin/sh"): @@ -417,6 +418,7 @@ self.assertEquals(next(it), "line2\n") self.assertEquals(next(it), "line3\n") self.assertRaises(StopIteration, next, it) + popen.close() # Verify environ keys and values from the OS are of the # correct str type.