Skip to content

Commit

Permalink
Fixed cleaning of messy output for port number.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Zeman authored and augi committed Jan 27, 2024
1 parent 56e6537 commit 581e186
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pytest_docker/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ def port_for(self, service, container_port):
)

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

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

0 comments on commit 581e186

Please sign in to comment.