Commit 6b08235a authored by Victor Stinner's avatar Victor Stinner

(Merge 3.4) Issue #18174: Fix leak of file descriptor in test_tempfile

parents 1bcab668 c61c170b
...@@ -762,8 +762,10 @@ class TestNamedTemporaryFile(BaseTestCase): ...@@ -762,8 +762,10 @@ class TestNamedTemporaryFile(BaseTestCase):
def test_no_leak_fd(self): def test_no_leak_fd(self):
# Issue #21058: don't leak file descriptor when io.open() fails # Issue #21058: don't leak file descriptor when io.open() fails
closed = [] closed = []
os_close = os.close
def close(fd): def close(fd):
closed.append(fd) closed.append(fd)
os_close(fd)
with mock.patch('os.close', side_effect=close): with mock.patch('os.close', side_effect=close):
with mock.patch('io.open', side_effect=ValueError): with mock.patch('io.open', side_effect=ValueError):
...@@ -1076,8 +1078,10 @@ if tempfile.NamedTemporaryFile is not tempfile.TemporaryFile: ...@@ -1076,8 +1078,10 @@ if tempfile.NamedTemporaryFile is not tempfile.TemporaryFile:
def test_no_leak_fd(self): def test_no_leak_fd(self):
# Issue #21058: don't leak file descriptor when io.open() fails # Issue #21058: don't leak file descriptor when io.open() fails
closed = [] closed = []
os_close = os.close
def close(fd): def close(fd):
closed.append(fd) closed.append(fd)
os_close(fd)
with mock.patch('os.close', side_effect=close): with mock.patch('os.close', side_effect=close):
with mock.patch('io.open', side_effect=ValueError): with mock.patch('io.open', side_effect=ValueError):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment