Skip to content

Commit 666bd86

Browse files
sf-mzaugi
authored andcommitted
Fixed cleaning of messy output for port number.
1 parent 16cbbb1 commit 666bd86

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/pytest_docker/plugin.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,14 @@ def port_for(self, service, container_port):
9090
)
9191

9292
# This handles messy output that might contain warnings or other text
93-
if len(endpoint.split("\n")) > 1:
94-
endpoint = endpoint.split("\n")[-1]
93+
ips = re.findall(r'\d{1,3}(?:\.\d{1,3}){3}:\d{1,5}', endpoint)
94+
if len(ips) == 0:
95+
raise ValueError(f'Could not found any IP in endpoint {endpoint} for "{service}:{container_port}"')
96+
if len(ips) > 1:
97+
raise ValueError(
98+
f'Found more IPs ({",".join(ips)}) in endpoint {endpoint} for "{service}:{container_port}". '
99+
f'Could not decided which port to use. ')
100+
endpoint = ips[0]
95101

96102
# Usually, the IP address here is 0.0.0.0, so we don't use it.
97103
match = int(endpoint.split(":", 1)[-1])

0 commit comments

Comments
 (0)