use addCleanup
This commit is contained in:
parent
ebe5d8ae3b
commit
556c7355dd
|
@ -2541,7 +2541,14 @@ class MiscIOTest(unittest.TestCase):
|
|||
|
||||
def _check_warn_on_dealloc_fd(self, *args, **kwargs):
|
||||
fds = []
|
||||
def cleanup_fds():
|
||||
for fd in fds:
|
||||
try:
|
||||
os.close(fd)
|
||||
except EnvironmentError as e:
|
||||
if e.errno != errno.EBADF:
|
||||
raise
|
||||
self.addCleanup(cleanup_fds)
|
||||
r, w = os.pipe()
|
||||
fds += r, w
|
||||
self._check_warn_on_dealloc(r, *args, **kwargs)
|
||||
|
@ -2552,13 +2559,6 @@ class MiscIOTest(unittest.TestCase):
|
|||
open(r, *args, closefd=False, **kwargs)
|
||||
support.gc_collect()
|
||||
self.assertEqual(recorded, [])
|
||||
finally:
|
||||
for fd in fds:
|
||||
try:
|
||||
os.close(fd)
|
||||
except EnvironmentError as e:
|
||||
if e.errno != errno.EBADF:
|
||||
raise
|
||||
|
||||
def test_warn_on_dealloc_fd(self):
|
||||
self._check_warn_on_dealloc_fd("rb", buffering=0)
|
||||
|
|
Loading…
Reference in New Issue