import socket

import pytest

import portend


def socket_infos():
	"""
	Generate addr infos for connections to localhost
	"""
	host = ''
	port = portend.find_available_local_port()
	infos = socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM)
	for info in infos:
		yield host, port, info


@pytest.fixture(params=list(socket_infos()))
def listening_addr(request):
	host, port, info = request.param
	af, socktype, proto, canonname, sa = info
	sock = socket.socket(af, socktype, proto)
	sock.bind(sa)
	sock.listen(5)
	try:
		yield sa
	finally:
		sock.close()


class TestCheckPort:
	def test_check_port_listening(self, listening_addr):
		with pytest.raises(IOError):
			portend._check_port(*listening_addr[:2])

@@ -180,15 +180,14 @@
 ()%0A%09
-infos =
+return
  soc
@@ -256,52 +256,180 @@
 AM)%0A
-%09for info in 
+%0A%0Adef id_for_info(info):%0A%09af, = info%5B:1%5D%0A%09return str(af)%0A%0Adef build_listening_
 infos
+()
 :%0A%09
-%09yield host, port, info
+params = list(socket_infos())%0A%09ids = list(map(id_for_info, params))%0A%09return locals()
 %0A%0A%0A@
@@ -447,26 +447,25 @@
 ure(
-params=list(socket
+**build_listening
 _inf
@@ -469,17 +469,16 @@
 infos())
-)
 %0Adef lis
@@ -503,42 +503,8 @@
 t):%0A
-%09host, port, info = request.param%0A
 %09af,
@@ -537,20 +537,29 @@
 e, sa = 
-info
+request.param
 %0A%09sock =

Refactor fixture to provide meaningful ids