Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e547b6

Browse files
committed
Issue #18174: Fix fd leaks in tests.
1 parent 409f902 commit 0e547b6

3 files changed

Lines changed: 5 additions & 1 deletion

File tree

Lib/test/test_openpty.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
class OpenptyTest(unittest.TestCase):
1111
def test(self):
1212
master, slave = os.openpty()
13+
self.addCleanup(os.close, master)
14+
self.addCleanup(os.close, slave)
1315
if not os.isatty(slave):
1416
self.fail("Slave-end of pty is not a terminal.")
1517

Lib/test/test_subprocess.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,8 @@ def _execute_child(self, *args, **kwargs):
12631263
self.stderr.fileno()),
12641264
msg="At least one fd was closed early.")
12651265
finally:
1266-
map(os.close, devzero_fds)
1266+
for fd in devzero_fds:
1267+
os.close(fd)
12671268

12681269
@unittest.skipIf(not os.path.exists("/dev/zero"), "/dev/zero required.")
12691270
def test_preexec_errpipe_does_not_double_close_pipes(self):

Lib/test/test_uuid.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ def testIssue8621(self):
458458

459459
else:
460460
os.close(fds[1])
461+
self.addCleanup(os.close, fds[0])
461462
parent_value = uuid.uuid4().hex
462463
os.waitpid(pid, 0)
463464
child_value = os.read(fds[0], 100).decode('latin-1')

0 commit comments

Comments
 (0)