diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -255,9 +255,8 @@ else: family = socket.AF_INET try: - s = socket.socket(family, socket.SOCK_STREAM) - s.bind(('localhost', port)) - s.close() + with socket.socket(family, socket.SOCK_STREAM) as s: + s.bind(('localhost', port)) return True except socket.error as exc: if exc.errno not in (