pytest-docker icon indicating copy to clipboard operation
pytest-docker copied to clipboard

Endpoint empty error

Open didacrarbones opened this issue 2 years ago • 5 comments

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

0.0.0.0:9997\r\n[0m

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?

didacrarbones avatar Feb 16 '22 15:02 didacrarbones

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?

n1ngu avatar Feb 16 '22 22:02 n1ngu

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 avatar Apr 21 '22 07:04 langustav

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.

langustav avatar Apr 21 '22 08:04 langustav

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

gbroll avatar May 02 '22 09:05 gbroll

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

langustav avatar May 18 '22 08:05 langustav