https://github.com/python/cpython/commit/ab0ad62038317a3d15099c23d2b0f03bee9f8fa7
commit: ab0ad62038317a3d15099c23d2b0f03bee9f8fa7
branch: main
author: Serhiy Storchaka <storch...@gmail.com>
committer: serhiy-storchaka <storch...@gmail.com>
date: 2024-01-10T12:38:36+02:00
summary:

gh-113879: Fix ResourceWarning in test_asyncio.test_server (GH-113881)

files:
M Lib/test/test_asyncio/test_server.py

diff --git a/Lib/test/test_asyncio/test_server.py 
b/Lib/test/test_asyncio/test_server.py
index f22cf3026e244b..918faac909b9bf 100644
--- a/Lib/test/test_asyncio/test_server.py
+++ b/Lib/test/test_asyncio/test_server.py
@@ -200,13 +200,13 @@ async def test_unix_server_sock_cleanup(self):
             async def serve(*args):
                 pass
 
-            sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-            sock.bind(addr)
+            with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
+                sock.bind(addr)
 
-            srv = await asyncio.start_unix_server(serve, sock=sock)
+                srv = await asyncio.start_unix_server(serve, sock=sock)
 
-            srv.close()
-            self.assertFalse(os.path.exists(addr))
+                srv.close()
+                self.assertFalse(os.path.exists(addr))
 
     @socket_helper.skip_unless_bind_unix_socket
     async def test_unix_server_cleanup_gone(self):
@@ -215,14 +215,14 @@ async def test_unix_server_cleanup_gone(self):
             async def serve(*args):
                 pass
 
-            sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-            sock.bind(addr)
+            with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
+                sock.bind(addr)
 
-            srv = await asyncio.start_unix_server(serve, sock=sock)
+                srv = await asyncio.start_unix_server(serve, sock=sock)
 
-            os.unlink(addr)
+                os.unlink(addr)
 
-            srv.close()
+                srv.close()
 
     @socket_helper.skip_unless_bind_unix_socket
     async def test_unix_server_cleanup_replaced(self):
@@ -234,11 +234,11 @@ async def serve(*args):
             srv = await asyncio.start_unix_server(serve, addr)
 
             os.unlink(addr)
-            sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-            sock.bind(addr)
+            with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
+                sock.bind(addr)
 
-            srv.close()
-            self.assertTrue(os.path.exists(addr))
+                srv.close()
+                self.assertTrue(os.path.exists(addr))
 
     @socket_helper.skip_unless_bind_unix_socket
     async def test_unix_server_cleanup_prevented(self):

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to