Bug: redis/windows: RedisContainer has no attributes '_container'
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
I thing it should be labeled as enhancement
Thanks for reporting, could you please provide the details from the issue template?
Sanity, working normally:
Win10 | Python 3.10 | Docker Desktop (WSL2) | testcontainers-v4.4.0
(Core tests are working)
(Redis tests are working)
Running test after stopping Docker:
Redis tests:
"Internal Server Error"
Core tests:
"Internal Server Error"
"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 :)
Another idea is avoiding this completely and adding a validation before running and/or testing that docker is even available 💡
@Tranquility2 i think it same as you, have no time to contribute - you can create pr and i can review
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 why not to make your code snippet a part of lib?
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.