# 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
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))
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):
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)
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
# 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):
fail(cert, 'example.net')
# -- IPv6 matching --
- if hasattr(socket, 'AF_INET6'):
+ if support.IPV6_ENABLED:
cert = {'subject': ((('commonName', 'example.com'),),),
'subjectAltName': (
('DNS', 'example.com'),
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))
--- /dev/null
+Fix test failures when IPv6 is unavailable or disabled.