diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-01-17 17:02:43 -0800 |
---|---|---|
committer | Ned Deily <nad@python.org> | 2019-01-17 20:02:43 -0500 |
commit | dc020cc9800ae85f3a241b89ff5fcbc35ba39406 (patch) | |
tree | 8383d5031fda01f1bc2b3fa375a4ff5a8814d82e | |
parent | 7eef540ab89e426b622373f43713521876447f2f (diff) | |
download | cpython-git-dc020cc9800ae85f3a241b89ff5fcbc35ba39406.tar.gz |
Make sure file object is close if socket.create_connection fails (GH-11334) (GH-11351)
The problem affects _testWithTimeoutTriggeredSend in test_socket.py.
(cherry picked from commit 1f511e1af060e98fb789319a96076c06e7f98135)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
-rw-r--r-- | Lib/test/test_socket.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 56adec18c6..95c3938ac2 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -5363,11 +5363,10 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest): def _testWithTimeoutTriggeredSend(self): address = self.serv.getsockname() - file = open(support.TESTFN, 'rb') - with socket.create_connection(address, timeout=0.01) as sock, \ - file as file: - meth = self.meth_from_sock(sock) - self.assertRaises(socket.timeout, meth, file) + with open(support.TESTFN, 'rb') as file: + with socket.create_connection(address, timeout=0.01) as sock: + meth = self.meth_from_sock(sock) + self.assertRaises(socket.timeout, meth, file) def testWithTimeoutTriggeredSend(self): conn = self.accept_conn() |