diff options
author | Florian Bruhin <me@the-compiler.org> | 2022-03-14 11:27:41 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2022-03-14 11:27:41 +0100 |
commit | b8c2c8d381243e0ff2e430b4eeab132c7b0114a6 (patch) | |
tree | bd92a74a9c5ede42c9c3c1f9a0aa6f2f48625860 | |
parent | db720b145436000208212f5fc2fff60a3d09e849 (diff) | |
download | qutebrowser-b8c2c8d381243e0ff2e430b4eeab132c7b0114a6.tar.gz qutebrowser-b8c2c8d381243e0ff2e430b4eeab132c7b0114a6.zip |
Simplify socket usage
-rw-r--r-- | tests/end2end/fixtures/webserver.py | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/tests/end2end/fixtures/webserver.py b/tests/end2end/fixtures/webserver.py index 81f75b338..2c2eab930 100644 --- a/tests/end2end/fixtures/webserver.py +++ b/tests/end2end/fixtures/webserver.py @@ -149,11 +149,9 @@ class WebserverProcess(testprocess.Process): def _random_port(self) -> int: """Get a random free port.""" - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.bind(('localhost', 0)) - port = sock.getsockname()[1] - sock.close() - return port + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: + sock.bind(('localhost', 0)) + return sock.getsockname()[1] def get_requests(self): """Get the requests to the server during this test.""" |