]> granicus.if.org Git - python/commitdiff
bpo-37199: Fix test failures when IPv6 is unavailable or disabled (GH-14480)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 30 Jun 2019 15:42:22 +0000 (08:42 -0700)
committerGitHub <noreply@github.com>
Sun, 30 Jun 2019 15:42:22 +0000 (08:42 -0700)
(cherry picked from commit c2cda638d63b98f5cf9a8ef13e15aace2b7e3f0b)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Lib/test/support/__init__.py
Lib/test/test_asyncio/test_base_events.py
Lib/test/test_socket.py
Lib/test/test_ssl.py
Misc/NEWS.d/next/Tests/2019-06-29-23-56-28.bpo-37199.FHDsLf.rst [new file with mode: 0644]

index ef623db87e0482d1d4e97e8a3616bc2f49369c9f..31b0dc8fc2ca39c56f20c81c69e244978356804d 100644 (file)
@@ -1491,6 +1491,8 @@ def get_socket_conn_refused_errs():
         # bpo-31910: socket.create_connection() fails randomly
         # with EADDRNOTAVAIL on Travis CI
         errors.append(errno.EADDRNOTAVAIL)
+    if not IPV6_ENABLED:
+        errors.append(errno.EAFNOSUPPORT)
     return errors
 
 
index 811b37425dd2877b3e13056e595875da240db6e6..08d4792fa72653fb593433b2593e2810997ce4ca 100644 (file)
@@ -91,6 +91,9 @@ class BaseEventTests(test_utils.TestCase):
         self.assertIsNone(
             base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, 0, 0))
 
+        if not support.IPV6_ENABLED:
+            return
+
         # IPv4 address with family IPv6.
         self.assertIsNone(
             base_events._ipaddr_info('1.2.3.4', 1, INET6, STREAM, TCP))
@@ -1149,7 +1152,7 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
             srv.close()
             self.loop.run_until_complete(srv.wait_closed())
 
-    @unittest.skipUnless(hasattr(socket, 'AF_INET6'), 'no IPv6 support')
+    @unittest.skipUnless(support.IPV6_ENABLED, 'no IPv6 support')
     def test_create_server_ipv6(self):
         async def main():
             with self.assertWarns(DeprecationWarning):
@@ -1281,6 +1284,9 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
             t.close()
             test_utils.run_briefly(self.loop)  # allow transport to close
 
+        if not support.IPV6_ENABLED:
+            return
+
         sock.family = socket.AF_INET6
         coro = self.loop.create_connection(asyncio.Protocol, '::1', 80)
         t, p = self.loop.run_until_complete(coro)
@@ -1298,6 +1304,7 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
             t.close()
             test_utils.run_briefly(self.loop)  # allow transport to close
 
+    @unittest.skipUnless(support.IPV6_ENABLED, 'no IPv6 support')
     @unittest.skipIf(sys.platform.startswith('aix'),
                     "bpo-25545: IPv6 scope id and getaddrinfo() behave differently on AIX")
     @patch_socket
index 74662cfeb327af598fdecf6147668dfa047948a1..db525642d6afcdd11918997649b983a3599d0d59 100644 (file)
@@ -4814,8 +4814,15 @@ class NetworkConnectionNoServer(unittest.TestCase):
         # Issue #9792: create_connection() should not recast timeout errors
         # as generic socket errors.
         with self.mocked_socket_module():
-            with self.assertRaises(socket.timeout):
+            try:
                 socket.create_connection((HOST, 1234))
+            except socket.timeout:
+                pass
+            except OSError as exc:
+                if support.IPV6_ENABLED or exc.errno != errno.EAFNOSUPPORT:
+                    raise
+            else:
+                self.fail('socket.timeout not raised')
 
 
 class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest):
index 7ba8156eef5da8a640b6a121937f409ff86436ab..38fdf3f375cc51bf61c51b31e513a18a2c4e52cb 100644 (file)
@@ -673,7 +673,7 @@ class BasicSocketTests(unittest.TestCase):
         fail(cert, 'example.net')
 
         # -- IPv6 matching --
-        if hasattr(socket, 'AF_INET6'):
+        if support.IPV6_ENABLED:
             cert = {'subject': ((('commonName', 'example.com'),),),
                     'subjectAltName': (
                         ('DNS', 'example.com'),
@@ -754,7 +754,7 @@ class BasicSocketTests(unittest.TestCase):
                 ssl._inet_paton(invalid)
         for ipaddr in ['127.0.0.1', '192.168.0.1']:
             self.assertTrue(ssl._inet_paton(ipaddr))
-        if hasattr(socket, 'AF_INET6'):
+        if support.IPV6_ENABLED:
             for ipaddr in ['::1', '2001:db8:85a3::8a2e:370:7334']:
                 self.assertTrue(ssl._inet_paton(ipaddr))
 
diff --git a/Misc/NEWS.d/next/Tests/2019-06-29-23-56-28.bpo-37199.FHDsLf.rst b/Misc/NEWS.d/next/Tests/2019-06-29-23-56-28.bpo-37199.FHDsLf.rst
new file mode 100644 (file)
index 0000000..b052091
--- /dev/null
@@ -0,0 +1 @@
+Fix test failures when IPv6 is unavailable or disabled.