summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-10-31 01:35:43 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-10-31 01:35:43 (GMT)
commit556c7355ddf06397f105b283986a7876218d7b26 (patch)
tree4c5e894cd914d7baf1d5d431bdefcb3b3d839866 /Lib/test/test_io.py
parentebe5d8ae3b43f03a48aa02eb11862d234678a01f (diff)
downloadcpython-556c7355ddf06397f105b283986a7876218d7b26.zip
cpython-556c7355ddf06397f105b283986a7876218d7b26.tar.gz
cpython-556c7355ddf06397f105b283986a7876218d7b26.tar.bz2
use addCleanup
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 04b3912..680e36d 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -2541,24 +2541,24 @@ class MiscIOTest(unittest.TestCase):
def _check_warn_on_dealloc_fd(self, *args, **kwargs):
fds = []
- try:
- r, w = os.pipe()
- fds += r, w
- self._check_warn_on_dealloc(r, *args, **kwargs)
- # When using closefd=False, there's no warning
- r, w = os.pipe()
- fds += r, w
- with warnings.catch_warnings(record=True) as recorded:
- open(r, *args, closefd=False, **kwargs)
- support.gc_collect()
- self.assertEqual(recorded, [])
- finally:
+ 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)
+ # When using closefd=False, there's no warning
+ r, w = os.pipe()
+ fds += r, w
+ with warnings.catch_warnings(record=True) as recorded:
+ open(r, *args, closefd=False, **kwargs)
+ support.gc_collect()
+ self.assertEqual(recorded, [])
def test_warn_on_dealloc_fd(self):
self._check_warn_on_dealloc_fd("rb", buffering=0)