Patchwork D9441: run-tests: use a context manager when looking for available ports

login
register
mail settings
Submitter phabricator
Date Nov. 28, 2020, 4:49 a.m.
Message ID <differential-rev-PHID-DREV-2lwbtyouolny3ar5c6oh-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47720/
State Superseded
Headers show

Comments

phabricator - Nov. 28, 2020, 4:49 a.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9441

AFFECTED FILES
  tests/run-tests.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

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 (