summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-12-29 02:12:39 (GMT)
committerGitHub <noreply@github.com>2018-12-29 02:12:39 (GMT)
commit0f756f7f564836d4f64e8f144e51f7f55346b919 (patch)
tree2312e2df8abb7b843b928da8e5478db72d83c47c
parent8f9228dd3a37c98876c9c8ff7fb0042650303474 (diff)
downloadcpython-0f756f7f564836d4f64e8f144e51f7f55346b919.zip
cpython-0f756f7f564836d4f64e8f144e51f7f55346b919.tar.gz
cpython-0f756f7f564836d4f64e8f144e51f7f55346b919.tar.bz2
Make sure file object is close if socket.create_connection fails (GH-11334)
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.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 9b9d113..82b89fc 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -5717,11 +5717,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()