avast / pytest-docker

Docker-based integration tests
MIT License
406 stars 68 forks source link

Endpoint empty error #78

Open didacrarbones opened 2 years ago

didacrarbones commented 2 years ago

On a windows system, the endpoint command returns a weird string:

0.0.0.0:9997\r\n

That's why the strip here does not change the string, and this line takes the garbage part. I have solved it by using a regexp:

ips = re.findall(r'[0-9]+(?:\.[0-9]+){3}:[0-9]+', endpoint)
assert len(ips) == 1
endpoint = ips[0]

Do you think this is a possible solution that could be merged in?

n1ngu commented 2 years ago

Looks like probably an escape character followed by a "reset color" shell sequence.

AFAIU the underlying subprocess shouldn't be using any decorations you have in your shell. Does your docker setup have some kind of colored output plugin?

langustav commented 2 years ago

I have run into the same issue. However, the problem is not with strip() but with following statement https://github.com/avast/pytest-docker/blob/master/src/pytest_docker/plugin.py#L87 It can been due to Windows 11. However, it is still bug on pytest_docker (and it is mentioned in the code that line 87 should handle a messy output. But the messy output has changed :) ) I would suggest similar solution. However, without assert (since it is not according to Python standards). I do not use any colored output plugin. Simple Docker desktop with default settings.

langustav commented 2 years ago

My proposal with proper exception handling would be something like this. Replacement for lines 86-87 :

ips = re.findall(r'[0-9]{1,3}(?:\.[0-9]{1,3}){3}:[0-9]{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]

However, there could be a problem if this endpoint will be in format: esfasf312sd:5664 (i.e., usage of hostname instead of IP). Also switching to IPv6 will be problematic with this approach.

gbroll commented 2 years ago

I have the same problem on win10, getting some weird output on line 78 (b'\r\n\x1b[0m') Running Docker Desktop 4.7.1 (77678) and docker-compose version 1.29.2, build 5becea4c

langustav commented 2 years ago

I have created a pull request for this issue: https://github.com/avast/pytest-docker/pull/81