Skip to content

Commit ab0ad62

Browse files
gh-113879: Fix ResourceWarning in test_asyncio.test_server (GH-113881)
1 parent 1b7e002 commit ab0ad62

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

Lib/test/test_asyncio/test_server.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@ async def test_unix_server_sock_cleanup(self):
200200
async def serve(*args):
201201
pass
202202

203-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
204-
sock.bind(addr)
203+
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
204+
sock.bind(addr)
205205

206-
srv = await asyncio.start_unix_server(serve, sock=sock)
206+
srv = await asyncio.start_unix_server(serve, sock=sock)
207207

208-
srv.close()
209-
self.assertFalse(os.path.exists(addr))
208+
srv.close()
209+
self.assertFalse(os.path.exists(addr))
210210

211211
@socket_helper.skip_unless_bind_unix_socket
212212
async def test_unix_server_cleanup_gone(self):
@@ -215,14 +215,14 @@ async def test_unix_server_cleanup_gone(self):
215215
async def serve(*args):
216216
pass
217217

218-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
219-
sock.bind(addr)
218+
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
219+
sock.bind(addr)
220220

221-
srv = await asyncio.start_unix_server(serve, sock=sock)
221+
srv = await asyncio.start_unix_server(serve, sock=sock)
222222

223-
os.unlink(addr)
223+
os.unlink(addr)
224224

225-
srv.close()
225+
srv.close()
226226

227227
@socket_helper.skip_unless_bind_unix_socket
228228
async def test_unix_server_cleanup_replaced(self):
@@ -234,11 +234,11 @@ async def serve(*args):
234234
srv = await asyncio.start_unix_server(serve, addr)
235235

236236
os.unlink(addr)
237-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
238-
sock.bind(addr)
237+
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
238+
sock.bind(addr)
239239

240-
srv.close()
241-
self.assertTrue(os.path.exists(addr))
240+
srv.close()
241+
self.assertTrue(os.path.exists(addr))
242242

243243
@socket_helper.skip_unless_bind_unix_socket
244244
async def test_unix_server_cleanup_prevented(self):

0 commit comments

Comments
 (0)