I have a simple Docker container from python:3.8.3
.
FROM python:3.8.3-alpine
RUN pip install --no-cache-dir fastapi python-multipart httpx pytest requests pytest-cov
COPY app ./app
COPY tests ./tests
COPY pytest.ini ./pytest.ini
WORKDIR /
I then run the container to execute pytest and generate a coverage file.
docker run -it testimage python -m pytest tests -v --cov=app --cov-report xml:/coverage.xml
Doing this I get the tests to run fine and that the xml file has been generated.
platform linux -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- /usr/local/bin/python
cachedir: .pytest_cache
rootdir: /, inifile: pytest.ini
plugins: cov-2.10.0
collected 11 items
...
tests/test_main.py::test_invalid_missing_params PASSED [100%]
----------- coverage: platform linux, python 3.8.3-final-0 -----------
Coverage XML written to file /coverage.xml
So all appears fine. I can run this command inside the container and see that the coverage.xml is generated too.
But when I try to get that file copied out of the container to artifact the coverage.xml
, or even just view the file to make sure it's there by appending && cat coverage.xml
to my run statement I always get: cat: coverage.xml: No such file or directory
.
So I'm not sure what I've done wrong here
I did also try using docker cp
and appending that to my run command.
&& docker cp testimage:/coverage.xml ~/Development/coverage.xml
but that too results in Error: No such container:path: testimage:/coverage.xml