bpo-37199: Fix test failures when IPv6 is unavailable or disabled (GH-14480)
(cherry picked from commit c2cda638d63b98f5cf9a8ef13e15aace2b7e3f0b)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 74662cf..db52564 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -4814,8 +4814,15 @@
# 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):