changeset 45955:064449f9fdc2

run-tests: use a context manager when looking for available ports Differential Revision: https://phab.mercurial-scm.org/D9441 Differential Revision: https://phab.mercurial-scm.org/D9452
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 29 Nov 2020 19:17:35 +0530
parents a120d1c9c704
children 40f79997e81f
files tests/run-tests.py
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Fri Nov 27 15:54:46 2020 -0500
+++ b/tests/run-tests.py	Sun Nov 29 19:17:35 2020 +0530
@@ -47,6 +47,7 @@
 
 import argparse
 import collections
+import contextlib
 import difflib
 import distutils.version as version
 import errno
@@ -255,9 +256,8 @@
     else:
         family = socket.AF_INET
     try:
-        s = socket.socket(family, socket.SOCK_STREAM)
-        s.bind(('localhost', port))
-        s.close()
+        with contextlib.closing(socket.socket(family, socket.SOCK_STREAM)) as s:
+            s.bind(('localhost', port))
         return True
     except socket.error as exc:
         if exc.errno not in (