Issue #18174: Fix fd leaks in tests.

This commit is contained in:
Richard Oudkerk 2013-06-10 16:29:19 +01:00
parent 409f90237c
commit 0e547b66dc
3 changed files with 5 additions and 1 deletions

View File

@ -10,6 +10,8 @@ if not hasattr(os, "openpty"):
class OpenptyTest(unittest.TestCase): class OpenptyTest(unittest.TestCase):
def test(self): def test(self):
master, slave = os.openpty() master, slave = os.openpty()
self.addCleanup(os.close, master)
self.addCleanup(os.close, slave)
if not os.isatty(slave): if not os.isatty(slave):
self.fail("Slave-end of pty is not a terminal.") self.fail("Slave-end of pty is not a terminal.")

View File

@ -1263,7 +1263,8 @@ class POSIXProcessTestCase(BaseTestCase):
self.stderr.fileno()), self.stderr.fileno()),
msg="At least one fd was closed early.") msg="At least one fd was closed early.")
finally: 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.") @unittest.skipIf(not os.path.exists("/dev/zero"), "/dev/zero required.")
def test_preexec_errpipe_does_not_double_close_pipes(self): def test_preexec_errpipe_does_not_double_close_pipes(self):

View File

@ -458,6 +458,7 @@ class TestUUID(unittest.TestCase):
else: else:
os.close(fds[1]) os.close(fds[1])
self.addCleanup(os.close, fds[0])
parent_value = uuid.uuid4().hex parent_value = uuid.uuid4().hex
os.waitpid(pid, 0) os.waitpid(pid, 0)
child_value = os.read(fds[0], 100).decode('latin-1') child_value = os.read(fds[0], 100).decode('latin-1')