diff -r c9545c2386c4 Lib/test/support.py --- a/Lib/test/support.py Wed Jul 03 23:07:59 2013 +0200 +++ b/Lib/test/support.py Wed Jul 03 23:52:05 2013 +0200 @@ -531,7 +531,7 @@ def find_unused_port(family=socket.AF_IN del tempsock return port -def bind_port(sock, host=HOST): +def bind_port(sock, host=HOST, flowinfo=0, scope_id=0): """Bind the socket to a free port and return the port number. Relies on ephemeral ports in order to ensure we are using an unbound port. This is important as many tests may be running simultaneously, especially in a @@ -558,7 +558,11 @@ def bind_port(sock, host=HOST): if hasattr(socket, 'SO_EXCLUSIVEADDRUSE'): sock.setsockopt(socket.SOL_SOCKET, socket.SO_EXCLUSIVEADDRUSE, 1) - sock.bind((host, 0)) + if sock.family == socket.AF_INET6: + addr = (host, 0, flowinfo, scope_id) + else: + addr = (host, 0) + sock.bind(addr) port = sock.getsockname()[1] return port diff -r c9545c2386c4 Lib/test/test_socket.py --- a/Lib/test/test_socket.py Wed Jul 03 23:07:59 2013 +0200 +++ b/Lib/test/test_socket.py Wed Jul 03 23:52:05 2013 +0200 @@ -538,13 +538,15 @@ class InetTestBase(SocketTestBase): """Base class for IPv4 socket tests.""" host = HOST + flowinfo = 0 + scope_id = 0 def setUp(self): super().setUp() self.port = self.serv_addr[1] def bindSock(self, sock): - support.bind_port(sock, host=self.host) + support.bind_port(sock, host=self.host, flowinfo=self.flowinfo, scope_id=self.scope_id) class TCPTestBase(InetTestBase): """Base class for TCP-over-IPv4 tests.""" @@ -574,9 +576,11 @@ class Inet6TestBase(InetTestBase): # has assigned it an IPv4-mapped address, then it's unlikely to # work with the full IPv6 API. host = "::1" + scope_id = 1 class UDP6TestBase(Inet6TestBase): """Base class for UDP-over-IPv6 tests.""" + scope_id = 1 def newSocket(self): return socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)