From dcd824f0f4429da66c420da3b2f381ea97466142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20=C4=8Cechovi=C4=8D?= Date: Mon, 26 May 2025 14:07:49 +0200 Subject: [PATCH 1/2] fix: docker host doesn't need to start with "tcp://" --- src/pytest_docker/plugin.py | 6 ++---- tests/test_docker_ip.py | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/pytest_docker/plugin.py b/src/pytest_docker/plugin.py index 317a209..df216cb 100644 --- a/src/pytest_docker/plugin.py +++ b/src/pytest_docker/plugin.py @@ -46,10 +46,8 @@ def get_docker_ip() -> Union[str, Any]: if not docker_host or docker_host.startswith("unix://"): return "127.0.0.1" - match = re.match(r"^tcp://(.+?):\d+$", docker_host) - if not match: - raise ValueError('Invalid value for DOCKER_HOST: "%s".' % (docker_host,)) - return match.group(1) + # Return just plain address without prefix and port + return re.sub(r"^[^:]+://(.+):\d+$", r"\1", docker_host) @pytest.fixture(scope=containers_scope) diff --git a/tests/test_docker_ip.py b/tests/test_docker_ip.py index e906a98..c8b109e 100644 --- a/tests/test_docker_ip.py +++ b/tests/test_docker_ip.py @@ -23,10 +23,8 @@ def test_docker_ip_unix() -> None: assert get_docker_ip() == "127.0.0.1" -@pytest.mark.parametrize("docker_host", ["http://1.2.3.4:2376"]) +@pytest.mark.parametrize("docker_host", ["http://1.2.3.4:2376", "tcp://1.2.3.4:2376"]) def test_docker_ip_remote_invalid(docker_host: str) -> None: environ = {"DOCKER_HOST": docker_host} with mock.patch("os.environ", environ): - with pytest.raises(ValueError) as exc: - print(get_docker_ip()) - assert str(exc.value) == ('Invalid value for DOCKER_HOST: "%s".' % (docker_host,)) + assert get_docker_ip() == "1.2.3.4" From be1e94708d8827f017f3db07a234ba3f576a2163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20August=C3=BDn?= Date: Mon, 26 May 2025 14:23:40 +0200 Subject: [PATCH 2/2] chore: version bump --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index bd2876e..2d6078e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pytest-docker -version = 3.2.1 +version = 3.2.2 description = Simple pytest fixtures for Docker and Docker Compose based tests long_description = file: README.md long_description_content_type = text/markdown