testcontainers / testcontainers-python

Testcontainers is a Python library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.

Home Page:https://testcontainers-python.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Are there plans to support python Flask servers?

davehouser1 opened this issue · comments

Not really a bug but wondering if Flask will be supported? We need a system that can deploy Flask containers configured as we decide and test with the API for each one.
If I should put this somewhere else me know.

how do you have your flask apps structured, like adjacent folders?

./apps/app1/pyproject.toml, ./apps/app1/app1/main.py
./apps/app2/pyproject.toml, ./apps/app2/app2/main.py

and then you want an integration test to live in ./apps/itest/e2e-{auth,apples,oranges}.py?

Actually we call instances of classes that build out a Flask app with specific responses and then start it with custom method that uses gevent()
So right now I have a bunch of classes I call to build each flask app.
We do this to perform auto testing, to make sure API calls come back the way we want in simple high level tests.
Curious if it would be easier to call testcontainers instead and just have it use my modules, to stand up containers instead of gevent instances.

hm, you can certainly containerize a python app arbitrarily with bind mounts, consider this java example - this app starts this other app as a containerized dependency. I simply pass the path to the jar (in this case would be app.py or the python file to run) here and launch by spinning up a generic java image, with my jar file copied into it here

if this is more or less the pattern i can try to replicate in python, should be totally possible. not sure if it is what you are trying to achieve

main takeaway - its not officially supported because it doesn't have to be, the framework is flexible enough to accomplish variety of use cases

Hi @davehouser1!

Sorry for the delays, if I understand correctly you are asking for a generic Flask container that can mount your app and run it.
However, any additional dependencies the app needs to function correctly becomes an inherent dependency!
It's not a good model to then "list dependencies, mount files, set CMD", instead it's far bettert to build your own container and run it via the GenericContainer.

There are some examples around in the repo on how to wait for healthy URLs, if that's a requirement for you.
Sorry for the delay on an answer, I hope this helps!