summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2019-06-30 15:24:43 (GMT)
committerAndrew Svetlov <andrew.svetlov@gmail.com>2019-06-30 15:24:43 (GMT)
commitc2cda638d63b98f5cf9a8ef13e15aace2b7e3f0b (patch)
treeed96b086ade6f8a2b2c3b589918636d450f64ad3
parent0d671c04c39b52e44597491b893eb0b6c86b3d45 (diff)
downloadcpython-c2cda638d63b98f5cf9a8ef13e15aace2b7e3f0b.zip
cpython-c2cda638d63b98f5cf9a8ef13e15aace2b7e3f0b.tar.gz
cpython-c2cda638d63b98f5cf9a8ef13e15aace2b7e3f0b.tar.bz2
bpo-37199: Fix test failures when IPv6 is unavailable or disabled (#14480)
-rw-r--r--Lib/test/support/__init__.py2
-rw-r--r--Lib/test/test_asyncio/test_base_events.py9
-rw-r--r--Lib/test/test_socket.py9
-rw-r--r--Lib/test/test_ssl.py4
-rw-r--r--Misc/NEWS.d/next/Tests/2019-06-29-23-56-28.bpo-37199.FHDsLf.rst1
5 files changed, 21 insertions, 4 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 19ea976..a65de4a 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -1493,6 +1493,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
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index 811b374..08d4792 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -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
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 50094de..e92f871 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -4964,8 +4964,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):
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index c72a857..064f0e8 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -676,7 +676,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'),
@@ -757,7 +757,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
index 0000000..b052091
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2019-06-29-23-56-28.bpo-37199.FHDsLf.rst
@@ -0,0 +1 @@
+Fix test failures when IPv6 is unavailable or disabled.