Tests: generalize IPv6 detection

This commit is contained in:
Unrud 2018-09-08 09:24:46 +02:00
parent 7760f4edf0
commit 94bb4fbdae

View File

@ -108,16 +108,18 @@ class TestBaseServerRequests:
assert status == 302 assert status == 302
def test_ipv6(self): def test_ipv6(self):
if (not server.HAS_IPV6 or os.environ.get("TRAVIS_OS_NAME") == "osx" or if not server.HAS_IPV6:
os.environ.get("TRAVIS_SUDO") == "true"): pytest.skip("IPv6 not supported")
pytest.skip("IPv6 not support")
if os.name == "nt" and server.EAI_ADDRFAMILY is None: if os.name == "nt" and server.EAI_ADDRFAMILY is None:
# HACK: incomplete errno conversion in WINE # HACK: incomplete errno conversion in WINE
server.EAI_ADDRFAMILY = -9 server.EAI_ADDRFAMILY = -9
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock: with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock:
sock.setsockopt(server.IPPROTO_IPV6, server.IPV6_V6ONLY, 1) sock.setsockopt(server.IPPROTO_IPV6, server.IPV6_V6ONLY, 1)
try:
# Find available port # Find available port
sock.bind(("::1", 0)) sock.bind(("::1", 0))
except OSError:
pytest.skip("IPv6 not supported")
self.sockname = sock.getsockname()[:2] self.sockname = sock.getsockname()[:2]
self.configuration["server"]["hosts"] = "[%s]:%d" % self.sockname self.configuration["server"]["hosts"] = "[%s]:%d" % self.sockname
self.thread.start() self.thread.start()