Skip to content

Commit

Permalink
test_socks: determine which localhosts work
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Booth committed Apr 20, 2019
1 parent 4379278 commit 89d6872
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tests/test_socks.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,23 @@ def data_received(self, data):
self.transport.write(self.response)


@pytest.fixture(params=['127.0.0.1', '::1', 'localhost'])
def localhosts():
candidates = ['127.0.0.1', '::1', 'localhost']
loop = asyncio.get_event_loop()
result = []
for host in candidates:
coro = loop.create_server(FakeServer, host=host, port=50001)
try:
server = loop.run_until_complete(coro)
except OSError as e:
result.append(pytest.param(host, marks=pytest.mark.skip))
else:
server.close()
result.append(host)
return result


@pytest.fixture(params=localhosts())
def proxy_address(request, event_loop, unused_tcp_port):
host = request.param
coro = event_loop.create_server(FakeServer, host=host, port=unused_tcp_port)
Expand Down

0 comments on commit 89d6872

Please sign in to comment.