Issue #18174: Fix fd leaks in tests.
authorRichard Oudkerk <shibturn@gmail.com>
Mon, 10 Jun 2013 15:29:19 +0000 (16:29 +0100)
committerRichard Oudkerk <shibturn@gmail.com>
Mon, 10 Jun 2013 15:29:19 +0000 (16:29 +0100)
Lib/test/test_openpty.py
Lib/test/test_subprocess.py
Lib/test/test_uuid.py

index e8175ff094d076e486feaef8f9cdf32a9f85d4ae..63843705b13af76f49c89380ac88583d632713e6 100644 (file)
@@ -10,6 +10,8 @@ if not hasattr(os, "openpty"):
 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.")
 
index 901d4dfbfbbf5787e0be79e7af2b71133f407382..4b904710931a285c9f9ea5d10338a2dba3d81f36 100644 (file)
@@ -1263,7 +1263,8 @@ class POSIXProcessTestCase(BaseTestCase):
                                      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):
index 016100d407cf0d14bb377815c8f55d7bf838606a..97ad6d0c2fb2e8914d9caa937bb531c7a6d7cb17 100644 (file)
@@ -458,6 +458,7 @@ class TestUUID(unittest.TestCase):
 
         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')