Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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