diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -47,6 +47,7 @@ import argparse import collections +import contextlib import difflib import distutils.version as version import errno @@ -255,7 +256,7 @@ else: family = socket.AF_INET try: - with socket.socket(family, socket.SOCK_STREAM) as s: + with contextlib.closing(socket.socket(family, socket.SOCK_STREAM)) as s: s.bind(('localhost', port)) return True except socket.error as exc: