changeset: 84081:46fe1bb0723c branch: 3.3 parent: 84078:ec854f76d6b9 user: Richard Oudkerk date: Mon Jun 10 16:29:19 2013 +0100 files: Lib/test/test_openpty.py Lib/test/test_subprocess.py Lib/test/test_uuid.py description: Issue #18174: Fix fd leaks in tests. diff -r ec854f76d6b9 -r 46fe1bb0723c Lib/test/test_openpty.py --- a/Lib/test/test_openpty.py Mon Jun 10 15:38:54 2013 +0100 +++ b/Lib/test/test_openpty.py Mon Jun 10 16:29:19 2013 +0100 @@ -10,6 +10,8 @@ class OpenptyTest(unittest.TestCase): def test(self): master, slave = os.openpty() + self.addCleanup(os.close, master) + self.addCleanup(os.close, slave) if not os.isatty(slave): self.fail("Slave-end of pty is not a terminal.") diff -r ec854f76d6b9 -r 46fe1bb0723c Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py Mon Jun 10 15:38:54 2013 +0100 +++ b/Lib/test/test_subprocess.py Mon Jun 10 16:29:19 2013 +0100 @@ -1263,7 +1263,8 @@ self.stderr.fileno()), msg="At least one fd was closed early.") finally: - map(os.close, devzero_fds) + for fd in devzero_fds: + os.close(fd) @unittest.skipIf(not os.path.exists("/dev/zero"), "/dev/zero required.") def test_preexec_errpipe_does_not_double_close_pipes(self): diff -r ec854f76d6b9 -r 46fe1bb0723c Lib/test/test_uuid.py --- a/Lib/test/test_uuid.py Mon Jun 10 15:38:54 2013 +0100 +++ b/Lib/test/test_uuid.py Mon Jun 10 16:29:19 2013 +0100 @@ -458,6 +458,7 @@ else: os.close(fds[1]) + self.addCleanup(os.close, fds[0]) parent_value = uuid.uuid4().hex os.waitpid(pid, 0) child_value = os.read(fds[0], 100).decode('latin-1')