Skip to content

bpo-37199: Fix test failures when IPv6 is unavailable or disabled #14480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
9 changes: 8 additions & 1 deletion Lib/test/test_asyncio/test_base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def test_ipaddr_info(self):
self.assertIsNone(
base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, 0, 0))

if not support.IPV6_ENABLED:
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this approach, because it's hard to see that the rest of the test is skipped. Please either split the test function into two or move the rest of the code into the if not supported.IPV6_ENABLED block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I am willing to make such changes, but I would like to hear what @asvetlov thinks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZackerySpytz please make a PR with changes suggested by @tiran

My first reaction was opening the source code to make sure that the return doesn't make harm.
On the other hand, I've committed the PR as is because you proposed a minimal possible diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I have created GH-14535.


# IPv4 address with family IPv6.
self.assertIsNone(
base_events._ipaddr_info('1.2.3.4', 1, INET6, STREAM, TCP))
Expand Down Expand Up @@ -1149,7 +1152,7 @@ def test_create_server_stream_bittype(self):
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):
Expand Down Expand Up @@ -1281,6 +1284,9 @@ def _test_create_connection_ip_addr(self, m_socket, allow_inet_pton):
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)
Expand All @@ -1298,6 +1304,7 @@ def _test_create_connection_ip_addr(self, m_socket, allow_inet_pton):
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
Expand Down
9 changes: 8 additions & 1 deletion Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -4964,8 +4964,15 @@ def test_create_connection_timeout(self):
# 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):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def fail(cert, hostname):
fail(cert, 'example.net')

# -- IPv6 matching --
if hasattr(socket, 'AF_INET6'):
if support.IPV6_ENABLED:
cert = {'subject': ((('commonName', 'example.com'),),),
'subjectAltName': (
('DNS', 'example.com'),
Expand Down Expand Up @@ -757,7 +757,7 @@ def fail(cert, hostname):
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))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix test failures when IPv6 is unavailable or disabled.