From 7b6baa43cd60e58ef072f77ed237f7b4acb2b276 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Thu, 26 Dec 2024 01:13:29 +0100 Subject: [PATCH] tests: remove custom system_has_ipv6() method --- test/conftest.py | 23 +++-------------------- test/requirements/python-requirements.txt | 1 + 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index a609908..8c2b44f 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -15,7 +15,7 @@ import pytest import requests from packaging.version import Version from docker.models.containers import Container - +from urllib3.util.connection import HAS_IPV6 logging.basicConfig(level=logging.INFO) logging.getLogger('backoff').setLevel(logging.INFO) @@ -40,23 +40,6 @@ test_container = 'nginx-proxy-pytest' # ############################################################################### -def system_has_ipv6() -> bool: - # See https://stackoverflow.com/a/66249915 - _ADDR_NOT_AVAIL = {errno.EADDRNOTAVAIL, errno.EAFNOSUPPORT} - _ADDR_IN_USE = {errno.EADDRINUSE} - - if not socket.has_ipv6: - return False - try: - with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock: - sock.bind(("::1", 0)) - return True - except OSError as e: - if e.errno in _ADDR_NOT_AVAIL: - return False - if e.errno in _ADDR_IN_USE: - return True - raise @contextlib.contextmanager def ipv6(force_ipv6=True): @@ -168,7 +151,7 @@ def container_ip(container: Container): """ global FORCE_CONTAINER_IPV6 if FORCE_CONTAINER_IPV6: - if not system_has_ipv6(): + if not HAS_IPV6: pytest.skip("This system does not support IPv6") ip = container_ipv6(container) if ip == '': @@ -272,7 +255,7 @@ def monkey_patch_urllib_dns_resolver(): # Fail early when querying IP directly, and it is forced ipv6 when not supported, # Otherwise a pytest container not using the host network fails to pass `test_raw-ip-vhost`. - if FORCE_CONTAINER_IPV6 and not system_has_ipv6(): + if FORCE_CONTAINER_IPV6 and not HAS_IPV6: pytest.skip("This system does not support IPv6") # custom DNS resolvers diff --git a/test/requirements/python-requirements.txt b/test/requirements/python-requirements.txt index fa176ae..e909603 100644 --- a/test/requirements/python-requirements.txt +++ b/test/requirements/python-requirements.txt @@ -3,3 +3,4 @@ docker==7.1.0 packaging==24.2 pytest==8.3.4 requests==2.32.3 +urllib3==2.3.0