Jc2k/pytest-docker-tools

Containers are removed on failed tests

alpex8 opened this issue · 2 comments

Hi,

when running tests that interact with a database, I would like to control weather or not the container is accessible after the test finishes / ends with error. This would be useful for analyzing purpose, e.g. to be able to have a look at the schema.
At best I would be able to control the behavior, in the way that I only keep containers of failed tests.

The docs are saying that the container factory supports all parameters of the docker library, so I tried the remove parameter. However I set remove=False, but however the container was deleted.

How could I achieve that containers aren't deleted after (failed) execution?

Jc2k commented

Hi

Sorry this isn't really supported right now and i'm not really sure how it would work if it was. 99% of what pytest-docker-tools is is cleaning up resources in the same way that a pytest tmpdir fixture cleans up after itself, so I don't really have an escape hatch.

Can you explain a bit more about your use case? Is it purely for manually inspecting things when you are debugging a prolem? What i do when a test fails is re-run the test with pytest --pdb. This holds the pytest session open and i can inspect the state of the running containers. I have also been known to make the test "hang" when i needed to test something (like adding a time.sleep(600000) sort of thing).

FWIW, remove=False would be passed through to docker, but it's not docker thats deleting the container, which is why it doesn't seem to work.

Hi,

thanks for letting me know about pytest --pdb. I wasn't aware of it. This may solve the issue described above.