Scrapy, a fast high-level web crawling & scraping framework for Python.
Bind both v4 and v6 in mockserver_ipv6. (#8360)
Andrey Rakhmatullin53d3bc7811ee
diff --git a/conftest.py b/conftest.pyindex 0c76d86cc..9a9ed20ce 100644--- a/conftest.py+++ b/conftest.py@@ -144,11 +144,15 @@ def mockserver() -> Generator[MockServer]:@pytest.fixture(scope="session")def mockserver_ipv6() -> Generator[MockServer]:- """A mockserver reachable only over the IPv6 loopback.+ """A mockserver addressed by the IPv6 loopback.Tests using this must skip when :func:`ipv6_loopback_available` is False."""- with MockServer("::1") as mockserver:+ # Where IPv6 sockets also accept IPv4, binding the IPv6 wildcard keeps+ # IPv4 servers from getting the same port numbers. Otherwise a client+ # resolving localhost to ::1 first would reach this server instead of+ # an IPv4 one.+ with MockServer("::") as mockserver:yield mockserverdiff --git a/tests/mockserver/http_base.py b/tests/mockserver/http_base.pyindex 8b93b767a..fada933c2 100644--- a/tests/mockserver/http_base.py+++ b/tests/mockserver/http_base.py@@ -34,15 +34,15 @@ class BaseMockServer(ABC):def __init__(self, host: str | None = None) -> None:"""Start a mockserver.- *host* is the address to listen on; by default every interface is bound- and requests are made to 127.0.0.1. Pass e.g. ``"::1"`` to test over- IPv6.+ *host* is the address to listen on; by default every IPv4 address is+ bound and requests are made to 127.0.0.1. Pass ``"::"`` to bind every+ IPv6 address instead, with requests made to ::1."""if not self.listen_http and not self.listen_https:raise ValueError("At least one of listen_http and listen_https must be set")self.proc: Popen[str] | None = None- self.host: str = host if host is not None else "127.0.0.1"+ self.host: str = "::1" if host == "::" else host or "127.0.0.1"self._listen_host: str | None = hostself.http_port: int | None = Noneself.https_port: int | None = None