Use with for the server

This ensures the server is closed correctly.
This commit is contained in:
Paul O'Leary McCann 2022-12-21 11:47:10 +09:00
parent eb390fb5f2
commit c362acb5ce

View File

@ -443,7 +443,7 @@ def test_find_available_port():
from wsgiref.simple_server import make_server, demo_app
httpd = make_server(host, port, demo_app)
with pytest.warns(UserWarning, match="already in use"):
found_port = find_available_port(port, host, auto_select_port=True)
assert found_port == port + 1, "Didn't find next port"
with make_server(host, port, demo_app) as httpd:
with pytest.warns(UserWarning, match="already in use"):
found_port = find_available_port(port, host, auto_select_port=True)
assert found_port == port + 1, "Didn't find next port"