]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-18174: Fix file descriptor leaks in tests (GH-7408)
authorVictor Stinner <vstinner@redhat.com>
Mon, 4 Jun 2018 22:36:42 +0000 (00:36 +0200)
committerGitHub <noreply@github.com>
Mon, 4 Jun 2018 22:36:42 +0000 (00:36 +0200)
* test_tempfile.test_no_leak_fd() mocks os.close() but it doesn't
  call the original os.close() method and so leaks an open file
  descriptor. Fix the test by calling the original os.close()
  function.
* test_posix.test_fdopen_directory(): close the directory file
  descriptor when the test completes.

Lib/test/test_posix.py
Lib/test/test_tempfile.py

index bce4e21e992b45696e8e19a8b9ae2376bdce50fd..c4283b604b96ab4fba05291413a956dea36de17a 100644 (file)
@@ -199,6 +199,7 @@ class PosixTester(unittest.TestCase):
     def test_fdopen_directory(self):
         try:
             fd = os.open('.', os.O_RDONLY)
+            self.addCleanup(os.close, fd)
         except OSError as e:
             self.assertEqual(e.errno, errno.EACCES)
             self.skipTest("system cannot open directories")
index 5c111a29ca60be1e8e8bc79870a39b083e2a34a4..2efb8362fe1bd5c72feb4a09bfe83b9b79fc4d1b 100644 (file)
@@ -821,6 +821,7 @@ class test_NamedTemporaryFile(TC):
         old_fdopen = os.fdopen
         closed = []
         def close(fd):
+            old_close(fd)
             closed.append(fd)
         def fdopen(*args):
             raise ValueError()