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

Not working on Windows

Open LostInDarkMath opened this issue 2 years ago • 6 comments

Hi there!

I'm using your library on Linux and it works fine. Now I tried it on WIndows (WIndows 10) and it doesn't work. Is there a way to make your library work with Windows?

Here is the error I'm getting:

Waiting for container to be ready.

test setup failed
mariadb_container = <pytest_docker_tools.wrappers.container.Container object at 0x0000020293B30460>

    @pytest.fixture(scope="session")
    def mariadb(mariadb_container):
>       mariadb_ip, mariadb_port = mariadb_container.get_addr('3306/tcp')

..\..\..\..\fixtures\mariadb.py:52: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pytest_docker_tools.wrappers.container.Container object at 0x0000020293B30460>
port = '3306/tcp'

    def get_addr(self, port):
        if tests_inside_container():
            return (self.ips.primary, int(port.split("/")[0]))
        else:
>           return ("127.0.0.1", self.ports[port][0])
E           IndexError: list index out of range

C:\Users\Test\AppData\Local\pypoetry\Cache\virtualenvs\maddox-IYXXq9hF-py3.10\lib\site-packages\pytest_docker_tools\wrappers\container.py:248: IndexError

I don't anything special in my code:

mariadb_container = container(
    name='{mariadb_service_name}',
    image='{mariadb_image.id}',
    ports={'3306/tcp': None},
    network='{test_net.name}',
    tmpfs={'/var/lib/mysql': ''},
    environment={
        'MYSQL_ROOT_PASSWORD': MARIA_DB_ROOT_PASSWORD,
    },
    scope="session",
    command="--innodb-ft-min-token-size=1",
    restart_policy={'Name': 'always'}
)

@pytest.fixture(scope="session")
def mariadb(mariadb_container):
    mariadb_ip, mariadb_port = mariadb_container.get_addr('3306/tcp')
    mariadb = MariaDBData(name=mariadb_container.name, host=mariadb_ip, port=mariadb_port, internal_port='3306',
                          username=MARIA_DB_USER, password=MARIA_DB_ROOT_PASSWORD, schema=DATABASE_NAME)
    return mariadb

How can I fix this?

LostInDarkMath avatar Aug 04 '22 16:08 LostInDarkMath

Hi! Sorry I only use Linux and macOS myself so I know very little about how Docker on Windows and how it differs. I certainly don't do any testing there.

The self.ports you see above is IIRC a wrapper around ["NetworkSettings"]["Ports"] as returned by the docker api. So someone with a Windows box needs to figure out why that field is different and what we can do instead.

Jc2k avatar Aug 04 '22 16:08 Jc2k

Thanks for your fast reply! I'll try to investigate.

LostInDarkMath avatar Aug 04 '22 16:08 LostInDarkMath

It's very strange: Sometimes it works fine but most of the time it fails with the error above. It seems to be flaky.

But there are also lots of other issues with your library on windows:

  1. reusable containers does not work
  2. Your tests aren't executable.

LostInDarkMath avatar Aug 04 '22 17:08 LostInDarkMath

I'm not surprised - I mean there are generally lots of failures when you port software to a completely new OS 😆 I would take patches for Windows support if (a) someone was willing to help maintain it and (b) we could get CI running for it.

I did look into (b), but whilst it's quite easy to do Python CI on Windows with GitHub actions, I don't think you could really test Docker for Windows on a Windows GitHub actions.

Unfortunately all my "volunteer" hours are set aside for Home Assistant, so i'm unlikely to be able to help much beyond patch review.

Jc2k avatar Aug 04 '22 18:08 Jc2k

Other alternatives would be executing tests in a container or using WSL to execute tests. The latter is supported in PyCharm Pro and I´ve found a WSL supporting extension for VSCode.

Maybe this are valid workarounds. This could even be mentioned in the READ.ME in case other users are affected as well.

alpex8 avatar Aug 05 '22 07:08 alpex8

Yes, I completely agee with you. The WSL seems to be a very good solution, I'll try it later in detail. I think it isn't worth the effort to make this package 100 % percent Windows compatible. But it would be very nice if you could add a section in the README.md that explains that this package is not designed to work on Windows and Windows users should use the WSL.

Using WSL with PyCharm Pro: https://www.jetbrains.com/help/pycharm/using-wsl-as-a-remote-interpreter.html

LostInDarkMath avatar Aug 05 '22 08:08 LostInDarkMath