From: Georg Brandl Date: Sat, 20 Nov 2010 14:16:17 +0000 (+0000) Subject: socket.gethostbyname(socket.gethostname()) can fail when host name resolution is... X-Git-Tag: v3.2b1~313 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=89197fe93c4a3f3e983721b0325b7bb5613c7e9c;p=python socket.gethostbyname(socket.gethostname()) can fail when host name resolution is not set up correctly; do not fail test_socket if this is the case. --- diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 57395b09d0..9f27a5120c 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -544,7 +544,11 @@ class GeneralModuleTests(unittest.TestCase): # XXX(nnorwitz): http://tinyurl.com/os5jz seems to indicate # it reasonable to get the host's addr in addition to 0.0.0.0. # At least for eCos. This is required for the S/390 to pass. - my_ip_addr = socket.gethostbyname(socket.gethostname()) + try: + my_ip_addr = socket.gethostbyname(socket.gethostname()) + except socket.error: + # Probably name lookup wasn't set up right; skip this test + return self.assertIn(name[0], ("0.0.0.0", my_ip_addr), '%s invalid' % name[0]) self.assertEqual(name[1], port) diff --git a/Misc/NEWS b/Misc/NEWS index 530cc6f4d9..b9e8d16364 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -46,6 +46,9 @@ C-API Tests ----- +- Do not fail test_socket when the IP address of the local hostname + cannot be looked up. + - Issue #8886: Use context managers throughout test_zipfile. Patch by Eric Carstensen.