testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

Bug: redis/windows: RedisContainer has no attributes '_container'

Open Vasiliy566 opened this issue 2 years ago • 8 comments

Describe the bug

Where docker did not started on running tests pc i get message

AttributeError: 'RedisContainer' object has no attribute '_container'

That is not informative

To Reproduce

Run any tests using testcontainers with docker stopped

AttributeError: 'RedisContainer' object has no attribute '_container'

Runtime environment

python 3.10

Vasiliy566 avatar Apr 03 '23 17:04 Vasiliy566

I thing it should be labeled as enhancement

Vasiliy566 avatar Apr 03 '23 17:04 Vasiliy566

Thanks for reporting, could you please provide the details from the issue template?

tillahoffmann avatar Apr 11 '23 16:04 tillahoffmann

Sanity, working normally: Win10 | Python 3.10 | Docker Desktop (WSL2) | testcontainers-v4.4.0 image image (Core tests are working) image (Redis tests are working) Running test after stopping Docker: image Redis tests: image "Internal Server Error" Core tests: image "Internal Server Error" image "Internal Server Error"

It all seems very much as expected when the Docker service is not available. Sorry to say but there is no indication of this issue or its a very specific/unique flow (that will require more info as @tillahoffmann requested).

If you have any ideas I'll keep the VM around :)

Tranquility2 avatar May 01 '24 10:05 Tranquility2

Another idea is avoiding this completely and adding a validation before running and/or testing that docker is even available 💡

Tranquility2 avatar May 01 '24 10:05 Tranquility2

@Tranquility2 i think it same as you, have no time to contribute - you can create pr and i can review

Vasiliy566 avatar May 02 '24 12:05 Vasiliy566

What i meant @Vasiliy566 is that you can wrap your usage with a try/except and check for this if needed:

try:
    from testcontainers.redis import RedisContainer
    from docker.errors import DockerException

    with RedisContainer() as redis_container:
        redis_client = redis_container.get_client()
except DockerException as exp:
    print(f"Failed to run test")
    if "Connection" in str(exp):
        print("Please check Docker connection is available")
Failed to run test
Please check Docker connection is available

Tranquility2 avatar May 05 '24 07:05 Tranquility2

@Tranquility2 why not to make your code snippet a part of lib?

Vasiliy566 avatar May 27 '24 14:05 Vasiliy566

In other Testcontainers language implementation, we verify the connection to Docker and perform some pre-flight checks to fail early. This would be preferable as compared to failing with such an internal error.

kiview avatar May 27 '24 14:05 kiview