Search code examples
dockerdockerfilepytest

pytest with docker image creating from Dockerfile


I am trying to create an docker image using a Dockerfile which I then try to run pytest on. I have following file structure:

├── Dockerfile
├── main
│   ├── src
│   │   └── main.py
│   └── test
│       └── test.py

My Dockerfile code looks like this:

FROM bitnami/spark:latest

RUN pip install pytest py4j

WORKDIR /app

COPY main /app

WORKDIR /app

CMD python -m pytest

I thought that if I copy my main folder should work but when I run my container it says there is nothing to test. I have tried this example Install pyspark + pytest in docker container and it works but problem here is that the example is not copying folders, only a single file.

Can anyone see what I need to do to run my pytest?


Solution

  • try renaming your test.py file to test_main.py

    Pytest documentation mentions: pytest searches for test_*.py or *_test.py files