Skip to content

Commit

Permalink
Skip test if no ipv6 on system detected (#1383)
Browse files Browse the repository at this point in the history
  • Loading branch information
euri10 committed Feb 24, 2022
1 parent 5cd29a2 commit 8585051
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/test_main.py
@@ -1,3 +1,4 @@
import socket
from logging import WARNING

import httpx
Expand Down Expand Up @@ -29,13 +30,33 @@ async def test_return_close_header():
)


def _has_ipv6(host):
sock = None
has_ipv6 = False
if socket.has_ipv6:
try:
sock = socket.socket(socket.AF_INET6)
sock.bind((host, 0))
has_ipv6 = True
except Exception:
pass
if sock:
sock.close()
return has_ipv6


@pytest.mark.asyncio
@pytest.mark.parametrize(
"host, url",
[
pytest.param(None, "http://127.0.0.1:8000", id="default"),
pytest.param("localhost", "http://127.0.0.1:8000", id="hostname"),
pytest.param("::1", "http://[::1]:8000", id="ipv6"),
pytest.param(
"::1",
"http://[::1]:8000",
id="ipv6",
marks=pytest.mark.skipif(not _has_ipv6("::1"), reason="IPV6 not enabled"),
),
],
)
async def test_run(host, url):
Expand Down

0 comments on commit 8585051

Please sign in to comment.