Skip to content

Commit dcd824f

Browse files
lexi-kaugi
authored andcommitted
fix: docker host doesn't need to start with "tcp://"
1 parent a0d51e5 commit dcd824f

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/pytest_docker/plugin.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ def get_docker_ip() -> Union[str, Any]:
4646
if not docker_host or docker_host.startswith("unix://"):
4747
return "127.0.0.1"
4848

49-
match = re.match(r"^tcp://(.+?):\d+$", docker_host)
50-
if not match:
51-
raise ValueError('Invalid value for DOCKER_HOST: "%s".' % (docker_host,))
52-
return match.group(1)
49+
# Return just plain address without prefix and port
50+
return re.sub(r"^[^:]+://(.+):\d+$", r"\1", docker_host)
5351

5452

5553
@pytest.fixture(scope=containers_scope)

tests/test_docker_ip.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ def test_docker_ip_unix() -> None:
2323
assert get_docker_ip() == "127.0.0.1"
2424

2525

26-
@pytest.mark.parametrize("docker_host", ["http://1.2.3.4:2376"])
26+
@pytest.mark.parametrize("docker_host", ["http://1.2.3.4:2376", "tcp://1.2.3.4:2376"])
2727
def test_docker_ip_remote_invalid(docker_host: str) -> None:
2828
environ = {"DOCKER_HOST": docker_host}
2929
with mock.patch("os.environ", environ):
30-
with pytest.raises(ValueError) as exc:
31-
print(get_docker_ip())
32-
assert str(exc.value) == ('Invalid value for DOCKER_HOST: "%s".' % (docker_host,))
30+
assert get_docker_ip() == "1.2.3.4"

0 commit comments

Comments
 (0)