]> granicus.if.org Git - python/commitdiff
socket.gethostbyname(socket.gethostname()) can fail when host name resolution is...
authorGeorg Brandl <georg@python.org>
Sat, 20 Nov 2010 14:16:17 +0000 (14:16 +0000)
committerGeorg Brandl <georg@python.org>
Sat, 20 Nov 2010 14:16:17 +0000 (14:16 +0000)
Lib/test/test_socket.py
Misc/NEWS

index 57395b09d02b0786dfdf1359da6936bd777ed76a..9f27a5120c5be45cd5e5e55b4871e1769c8319ee 100644 (file)
@@ -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)
 
index 530cc6f4d9667e8841266cd739b7a32618e48fa7..b9e8d1636441911bade523a517aa0b0cc39b7e9a 100644 (file)
--- 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.