Run py.test in the docker container as a service

I am working on a dockerized selenium net. I can send my python tests [run with pytest] from the pytest container [see Below] by joining him. But I installed another LAMP container that will manage pytest. Therefore, I want to make the pytest container standalone by working in standby mode and waiting for commands from the LAMP container.

I have this Docker file:

# Starting from base image FROM ubuntu #----------------------------------------------------- # Set the Github personal token ENV GH_TOKEN blablabla # Install Python & pip RUN apt-get update RUN apt-get upgrade -y RUN apt-get install -y python python-pip python-dev && pip install --upgrade pip # Install nano for #debugging RUN apt-get install -y nano # Install xvfb RUN apt-get install -y xvfb # Install GIT RUN apt-get update -y && apt-get install git -y # [in the / folder] RUN git clone https://$GH_TOKEN: x-oauth-basic@github.com /user/project.git /project # Install dependencies via pip WORKDIR /project RUN pip install -r dependencies.txt #----------------------------------------------------- # CMD ["/bin/bash"] 

I run the pytest container manually [for development] using this:

 docker run -dit -v /project --name pytest repo/user:py 

The thing is, I finished the development, and I want to run the pytest container from docker-compose and connect it to other containers [with reference and scope]. I just can't make him stay.

I used this:

 pytest: image: repo/user:py volumes: - "/project" command: "/bin/bash tail -f /dev/null" 

but does not work.

So, should a specific CMD or ENTRYPOINT be used inside the Dockerfile?

Should I use some command from docker-compose file?

+7
python docker docker-compose dockerfile
source share
1 answer

I'm not quite sure how your tests are performed, but I think I have the same use case. You can see how I do this in my Envoy project in cmd.sh and a sample test .

This is how I run my tests. I also use pytest, but it doesn’t matter: 1. use docker-composition to raise the stack, without tests 2. Wait until the stack is ready for requests. for me, this means polling for an answer of 200 3. Run the test container separately, but make sure that it uses the same network as the composite stack.

There are several ways to do this. You can put it all in a Bash script and manage it all from your host.

In my case, I am doing all this from a Python container. Its not much to wrap your head around, but the idea is that there is a Python test container that starts the host. Then the container itself uses compose to return the stack back to the host (dockerement). And then in the test container we run the pytest test. When this is done, it folds the stack and pushes the return code.

+1
source share

All Articles