Running pytest command outside of docker container failes because container stopped

Viewed 442

I use docker selenium grid and pytest to execute tests. What i now do is:

  • Spin up selenium grid via a makerfile
  • Spin up the docker container (with a volume pointing to my local pc for the tests). The container also runs the pytest command.

This all works good, except that i would rather split the second action and be able to run the test on an already running container. Preferred setup:

  • Spin up selenium grid + docker container with pyton+pytest
  • A command to run the tests (with the container as interpretor)

When i tried to do this, i faced the issue that the python+pytest container stops running when the commands are all done. There is no long living process.

Dockerfile
FROM python:3.9.0-alpine
RUN apk add tk

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
RUN ls ..

CMD pytest --junitxml ../r/latest.xml

My docker-compose file looks like:

docker-compose.yml
version: "3.0"
services:

  pytest:
    container_name: pytest
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ./t:/t 
      - ./r:/r 
    working_dir: /t/

networks:
  default:
      name: my_local_network #same as selenium grid

It does not 'feel' good to have this pytest command in the container settings itself.

0 Answers
Related