Fix resourcewarnings in websocket tests

This commit is contained in:
Kovid Goyal 2024-08-26 16:08:12 +05:30
parent 60555c1389
commit 08e7cddeb0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -165,6 +165,12 @@ class WSClient:
reason = reason.encode('utf-8')
self.write_frame(1, CLOSE, struct.pack(b'!H', code) + reason)
def __enter__(self):
return self
def __exit__(self, *a):
self.socket.close()
class WSTestServer(TestServer):
@ -184,7 +190,7 @@ class WSTestServer(TestServer):
class WebSocketTest(BaseTest):
def simple_test(self, server, msgs, expected=(), close_code=NORMAL_CLOSE, send_close=True, close_reason=b'NORMAL CLOSE', ignore_send_failures=False):
client = server.connect()
with server.connect() as client:
for msg in msgs:
try:
if isinstance(msg, dict):