Skip to content

Commit 4a03fae

Browse files
authored
use a context manager for context.wrap_socket
1 parent 96ea20c commit 4a03fae

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

pytest_httpbin/serve.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,11 @@ def finish_request(self, request, client_address):
6565
os.path.join(CERT_DIR, "cert.pem"),
6666
os.path.join(CERT_DIR, "key.pem"),
6767
)
68-
ssock = context.wrap_socket(
68+
with context.wrap_socket(
6969
request, server_side=True, suppress_ragged_eofs=False
70-
)
71-
try:
70+
) as ssock:
7271
self.base_environ["HTTPS"] = "yes"
7372
self.RequestHandlerClass(ssock, client_address, self)
74-
finally:
75-
ssock.close()
7673
except Exception as e:
7774
print("pytest-httpbin server hit an exception serving request: %s" % e)
7875
print("attempting to ignore so the rest of the tests can run")

0 commit comments

Comments
 (0)