Python pytest期间拒绝权限--travis ci中docker上的cov执行
我在travisci端docker上执行pytest命令时遇到问题。执行命令后:Python pytest期间拒绝权限--travis ci中docker上的cov执行,python,docker,travis-ci,coveralls,Python,Docker,Travis Ci,Coveralls,我在travisci端docker上执行pytest命令时遇到问题。执行命令后: docker exec my_package pytest --cov=/usr/local/lib/python3.7/site-packages/my_package tests/ -vvv 以下错误可见: tests/test_views/test_users.py::test_get_users PASSED [100%] INTERNALERROR> Trac
docker exec my_package pytest --cov=/usr/local/lib/python3.7/site-packages/my_package tests/ -vvv
以下错误可见:
tests/test_views/test_users.py::test_get_users PASSED [100%]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/usr/local/lib/python3.7/site-packages/_pytest/main.py", line 209, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "/usr/local/lib/python3.7/site-packages/_pytest/main.py", line 249, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/usr/local/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 68, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 62, in <lambda>
INTERNALERROR> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR> File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 203, in _multicall
INTERNALERROR> gen.send(outcome)
INTERNALERROR> File "/usr/local/lib/python3.7/site-packages/pytest_cov/plugin.py", line 229, in pytest_runtestloop
INTERNALERROR> self.cov_controller.finish()
INTERNALERROR> File "/usr/local/lib/python3.7/site-packages/pytest_cov/engine.py", line 167, in finish
INTERNALERROR> self.cov.stop()
INTERNALERROR> File "/usr/local/lib/python3.7/site-packages/coverage/control.py", line 782, in save
INTERNALERROR> self.data_files.write(self.data, suffix=self.data_suffix)
INTERNALERROR> File "/usr/local/lib/python3.7/site-packages/coverage/data.py", line 680, in write
INTERNALERROR> data.write_file(filename)
INTERNALERROR> File "/usr/local/lib/python3.7/site-packages/coverage/data.py", line 467, in write_file
INTERNALERROR> with open(filename, 'w') as fdata:
INTERNALERROR> PermissionError: [Errno 13] Permission denied: '/code/.coverage'
Dockerfile
FROM python:3.7
WORKDIR /code
RUN apt-get update && apt-get install -y musl-dev gcc postgresql
ADD requirements-test.txt /code/
RUN pip3 -r requirements-test.txt
COPY . /code
RUN pip3 install .
EXPOSE 5000
RUN useradd user
USER user
您是否尝试过运行
runuseradduser;用户用户
在运行apt get后?由于以root用户身份运行COPY
,代码覆盖率结果可能无法写入root用户创建的文件夹,从而导致问题
FROM python:3.7
WORKDIR /code
RUN apt-get update && apt-get install -y musl-dev gcc postgresql
ADD requirements-test.txt /code/
RUN pip3 -r requirements-test.txt
COPY . /code
RUN pip3 install .
EXPOSE 5000
RUN useradd user
USER user