Skip to content

Commit c2684c6

Browse files
bpo-37199: Fix test failures when IPv6 is unavailable or disabled (GH-14480)
(cherry picked from commit c2cda63) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
1 parent bf8cb31 commit c2684c6

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

‎Lib/test/support/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,8 @@ def get_socket_conn_refused_errs():
14911491
# bpo-31910: socket.create_connection() fails randomly
14921492
# with EADDRNOTAVAIL on Travis CI
14931493
errors.append(errno.EADDRNOTAVAIL)
1494+
if not IPV6_ENABLED:
1495+
errors.append(errno.EAFNOSUPPORT)
14941496
return errors
14951497

14961498

‎Lib/test/test_asyncio/test_base_events.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ def test_ipaddr_info(self):
9191
self.assertIsNone(
9292
base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, 0, 0))
9393

94+
if not support.IPV6_ENABLED:
95+
return
96+
9497
# IPv4 address with family IPv6.
9598
self.assertIsNone(
9699
base_events._ipaddr_info('1.2.3.4', 1, INET6, STREAM, TCP))
@@ -1149,7 +1152,7 @@ def test_create_server_stream_bittype(self):
11491152
srv.close()
11501153
self.loop.run_until_complete(srv.wait_closed())
11511154

1152-
@unittest.skipUnless(hasattr(socket, 'AF_INET6'), 'no IPv6 support')
1155+
@unittest.skipUnless(support.IPV6_ENABLED, 'no IPv6 support')
11531156
def test_create_server_ipv6(self):
11541157
async def main():
11551158
with self.assertWarns(DeprecationWarning):
@@ -1281,6 +1284,9 @@ def _test_create_connection_ip_addr(self, m_socket, allow_inet_pton):
12811284
t.close()
12821285
test_utils.run_briefly(self.loop) # allow transport to close
12831286

1287+
if not support.IPV6_ENABLED:
1288+
return
1289+
12841290
sock.family = socket.AF_INET6
12851291
coro = self.loop.create_connection(asyncio.Protocol, '::1', 80)
12861292
t, p = self.loop.run_until_complete(coro)
@@ -1298,6 +1304,7 @@ def _test_create_connection_ip_addr(self, m_socket, allow_inet_pton):
12981304
t.close()
12991305
test_utils.run_briefly(self.loop) # allow transport to close
13001306

1307+
@unittest.skipUnless(support.IPV6_ENABLED, 'no IPv6 support')
13011308
@unittest.skipIf(sys.platform.startswith('aix'),
13021309
"bpo-25545: IPv6 scope id and getaddrinfo() behave differently on AIX")
13031310
@patch_socket

‎Lib/test/test_socket.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4814,8 +4814,15 @@ def test_create_connection_timeout(self):
48144814
# Issue #9792: create_connection() should not recast timeout errors
48154815
# as generic socket errors.
48164816
with self.mocked_socket_module():
4817-
with self.assertRaises(socket.timeout):
4817+
try:
48184818
socket.create_connection((HOST, 1234))
4819+
except socket.timeout:
4820+
pass
4821+
except OSError as exc:
4822+
if support.IPV6_ENABLED or exc.errno != errno.EAFNOSUPPORT:
4823+
raise
4824+
else:
4825+
self.fail('socket.timeout not raised')
48194826

48204827

48214828
class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest):

‎Lib/test/test_ssl.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ def fail(cert, hostname):
673673
fail(cert, 'example.net')
674674

675675
# -- IPv6 matching --
676-
if hasattr(socket, 'AF_INET6'):
676+
if support.IPV6_ENABLED:
677677
cert = {'subject': ((('commonName', 'example.com'),),),
678678
'subjectAltName': (
679679
('DNS', 'example.com'),
@@ -754,7 +754,7 @@ def fail(cert, hostname):
754754
ssl._inet_paton(invalid)
755755
for ipaddr in ['127.0.0.1', '192.168.0.1']:
756756
self.assertTrue(ssl._inet_paton(ipaddr))
757-
if hasattr(socket, 'AF_INET6'):
757+
if support.IPV6_ENABLED:
758758
for ipaddr in ['::1', '2001:db8:85a3::8a2e:370:7334']:
759759
self.assertTrue(ssl._inet_paton(ipaddr))
760760

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix test failures when IPv6 is unavailable or disabled.

0 commit comments

Comments
 (0)