Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2cda63

Browse files
ZackerySpytzasvetlov
authored andcommitted
bpo-37199: Fix test failures when IPv6 is unavailable or disabled (#14480)
1 parent 0d671c0 commit c2cda63

5 files changed

Lines changed: 21 additions & 4 deletions

File tree

Lib/test/support/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,8 @@ def get_socket_conn_refused_errs():
14931493
# bpo-31910: socket.create_connection() fails randomly
14941494
# with EADDRNOTAVAIL on Travis CI
14951495
errors.append(errno.EADDRNOTAVAIL)
1496+
if not IPV6_ENABLED:
1497+
errors.append(errno.EAFNOSUPPORT)
14961498
return errors
14971499

14981500

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
@@ -4964,8 +4964,15 @@ def test_create_connection_timeout(self):
49644964
# Issue #9792: create_connection() should not recast timeout errors
49654965
# as generic socket errors.
49664966
with self.mocked_socket_module():
4967-
with self.assertRaises(socket.timeout):
4967+
try:
49684968
socket.create_connection((HOST, 1234))
4969+
except socket.timeout:
4970+
pass
4971+
except OSError as exc:
4972+
if support.IPV6_ENABLED or exc.errno != errno.EAFNOSUPPORT:
4973+
raise
4974+
else:
4975+
self.fail('socket.timeout not raised')
49694976

49704977

49714978
class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest):

Lib/test/test_ssl.py

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

678678
# -- IPv6 matching --
679-
if hasattr(socket, 'AF_INET6'):
679+
if support.IPV6_ENABLED:
680680
cert = {'subject': ((('commonName', 'example.com'),),),
681681
'subjectAltName': (
682682
('DNS', 'example.com'),
@@ -757,7 +757,7 @@ def fail(cert, hostname):
757757
ssl._inet_paton(invalid)
758758
for ipaddr in ['127.0.0.1', '192.168.0.1']:
759759
self.assertTrue(ssl._inet_paton(ipaddr))
760-
if hasattr(socket, 'AF_INET6'):
760+
if support.IPV6_ENABLED:
761761
for ipaddr in ['::1', '2001:db8:85a3::8a2e:370:7334']:
762762
self.assertTrue(ssl._inet_paton(ipaddr))
763763

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)