0

Docker File

ARG SOURCE_IMAGE
FROM ${SOURCE_IMAGE}

# How to Mount a volume and run Pytest from
# https://stackoverflow.com/questions/35322452/is-there-a-way-to-sandbox-test-execution-with-pytest-especially-filesystem-acce

RUN adduser --disabled-password --gecos "" --uid 7357 pytest
COPY ./ /home/pytest
WORKDIR /home/pytest

# setup the python and pytest environments
RUN pip install --upgrade pip setuptools pytest
RUN pip install --upgrade -r requirements.txt
RUN pip install --upgrade -r requirements_dev.txt
RUN python setup.py develop

# setup entry point
USER pytest
ENTRYPOINT ["/bin/bash", "-l", "-c"]

Run Invocations With Output

docker run --rm --mount source=example,target=/home/pytest example_pytest  pytest
============================= test session starts ==============================
platform linux -- Python 3.7.2, pytest-4.2.1, py-1.7.0, pluggy-0.8.1
benchmark: 3.2.2 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision$
10 warmup=False warmup_iterations=100000)
rootdir: /home/pytest, inifile: setup.cfg
plugins: cov-2.6.1, benchmark-3.2.2
collected 1 item

tests/test_example.py .                                                  [100%]

=========================== 1 passed in 0.05 seconds ===========================

Run Invocations Without Output

docker run -a stdin -a stdout -a stderr --rm --mount source=example,target=/home/pytest example_pytest  python -m mypy --ignore-missing
-imports --disallow-untyped-defs example
docker run -a stdin -a stdout -a stderr --rm --mount source=example,target=/home/pytest example_pytest python --version
docker run -a stdin -a stdout -a stderr --rm --mount source=example,target=/home/pytest example_pytest python -m pytest
AlexLordThorsen
  • 8,057
  • 5
  • 48
  • 103

1 Answers1

0

Solution

I ended up removing the ENTRYPOINT ["/bin/bash", "-l", "-c"] portion of the Dockerfile and I was able to see the output from the run commands.

Invocations With Working Output

docker run -a stdin -a stdout -a stderr --rm --mount source=example,target=/home/pytest example_pytest  python -m mypy --ignore-missing
-imports --disallow-untyped-defs example
docker run -a stdin -a stdout -a stderr --rm --mount source=example,target=/home/pytest example_pytest python --version
Python 3.7.2
docker run -a stdin -a stdout -a stderr --rm --mount source=example,target=/home/pytest example_pytest python -m pytest
============================= test session starts ==============================
platform linux -- Python 3.7.2, pytest-4.2.1, py-1.7.0, pluggy-0.8.1
benchmark: 3.2.2 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=
10 warmup=False warmup_iterations=100000)
rootdir: /home/pytest, inifile: setup.cfg
plugins: cov-2.6.1, benchmark-3.2.2
collected 1 item

tests/test_example.py .                                                  [100%]

=========================== 1 passed in 0.05 seconds ===========================
AlexLordThorsen
  • 8,057
  • 5
  • 48
  • 103