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

Option to auto-start the Docker container for tests

Open sanders41 opened this issue 4 years ago • 3 comments

For my projects that use Python and Docker together I have created an autouse session scoped fixture to automatically start the Docker container if it isn't running. The way it work is it checks the expected port (port 7700 in this case) at startup and if the port is in use it assumes the container is already running so it does nothing. If nothing is running on the port it starts the container for the tests, then stop it when the tests complete.

Because it first checks for a running container there would be no changes made to the current CI workflow because the fixture would see that the container is already running not start a new one. The same would be true if you still want to start you own container before testing, nothing would change from how it currently works in this scenario.

The difference would be that if you don't start a container before running the test suite, a container would automatically start for you so the tests wouldn't fail (at least not because there was no container running).

Would there be any interest in adding this fixture to this project? Or maybe not everyone is using Docker to run the tests here? If that is the case it should still work as expected if MeiliSearch is running on port 7700 (the fixture should see this and not start a container). If there is interest in using the fixture, I could test this scenario to be sure it works as expected.

sanders41 avatar Mar 02 '21 13:03 sanders41

Hey @sanders41 that is a nice idea! Just to be sure about this: if I have a running container at 7700 then the tests will run on this container? You said " it assumes the container is already running so it does nothing", does this mean "it doesn't create a new container but still run the tests"? Or "It doesn't even run the tests"?

eskombro avatar Mar 02 '21 13:03 eskombro

Correct, the only thing the fixture does is start the container if needed, it doesn't change any other part of the test and they still run just as they do now if a container is started before the tests are run.

If you like I already have the fixture created in other projects so it would only take a second to add it to this one. I could open a PR so you can see what I mean, and it would be no real loss of time on my side if you don't like it and want to close it.

sanders41 avatar Mar 02 '21 13:03 sanders41

Ok in that case it would be great to see, IMO it seems like a great addition! 🎉

eskombro avatar Mar 02 '21 14:03 eskombro

@alallema I forgot about this and just noticed it is still open. I never did figure out why it was flaky with the Meilisearch container.

I'm doing it differently now using just and this has had no issues. Here is what I am using now. For the testing you run just test and this starts the docker container, runs the tests, then stops the container when it is done.

If you like the just idea and want to set it up I can do that, or if not I think it makes sense to close this issue. Either way is OK for me :smiley:

sanders41 avatar May 11 '23 19:05 sanders41