alt_tests_conftest_py.patch | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/alt_tests_conftest_py.patch b/alt_tests_conftest_py.patch new file mode 100644 index 00000000..f9c0a885 --- /dev/null +++ b/alt_tests_conftest_py.patch @@ -0,0 +1,49 @@ +diff --git a/tests/conftest.py b/tests/conftest.py +index 7ce08966..189971b1 100644 +--- a/tests/conftest.py ++++ b/tests/conftest.py +@@ -4,9 +4,9 @@ import os + import socket + import ssl + import sys ++from itertools import count + from pathlib import Path + +-import ephemeral_port_reserve + import pytest + from xprocess import ProcessStarter + +@@ -15,6 +15,24 @@ from werkzeug.utils import cached_property + run_path = str(Path(__file__).parent / "live_apps" / "run.py") + + ++def get_free_port(): ++ gen_port = count(49152) ++ s = socket.socket() ++ s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) ++ ++ while True: ++ port = next(gen_port) ++ ++ try: ++ s.bind(("127.0.0.1", port)) ++ except OSError: ++ continue ++ ++ s.close() ++ return port ++ ++ ++ + class UnixSocketHTTPConnection(http.client.HTTPConnection): + def connect(self): + self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) +@@ -29,7 +47,7 @@ class DevServerClient: + port = kwargs.get("port") + + if port is None: +- kwargs["port"] = port = ephemeral_port_reserve.reserve(host) ++ kwargs["port"] = port = port = get_free_port() + + scheme = "https" if "ssl_context" in kwargs else "http" + self.addr = f"{host}:{port}"