容器内部的Pytest错误-导入测试模块时ImportError

时间:2019-05-06 17:47:02

标签: python-3.x docker pytest

container内运行pytest时出现此错误。如何解决此错误?我可以从pycharm和Windows Shell运行相同的程序包。那是在我设置了PYTHONPATH之后。

ImportError while importing test module '/testsuite/comments_posts_api/test_put_comments_post_byid.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
comments_posts_api/test_put_comments_post_byid.py:6: in <module>
    from service_layer.post import Post
E   ModuleNotFoundError: No module named 'service_layer'
# Pull base image
From ubuntu:18.04

# Install dependencies
RUN apt-get update -y
RUN apt-get install -y build-essential python3.6 python3.6-dev python3-pip python3.6-venv
RUN apt-get install -y vim
RUN python3.6 -m pip install pip --upgrade
RUN pip3 install pylint
RUN pip3 install requests
RUN pip3 install pytest pytest-cache

#install dos2unix
RUN apt-get update && \
    apt-get install dos2unix && \
    apt-get clean

# Create working directory
RUN mkdir /testsuite

# Copy project
COPY comments_categories_api  /testsuite/comments_categories_api/
COPY comments_posts_api  /testsuite/comments_posts_api/
COPY service_layer /testsuite/service_layer/
RUN chmod -R a+rwX testsuite/
# Set working directory

WORKDIR /testsuite
# Set Python version
RUN echo alias python='/usr/bin/python3' >> ~/.bashrc
# RUN echo cd testsuite/ >> ~/.bashrc

COPY ./docker-entrypoint.sh /testsuite/docker-entrypoint.sh
RUN dos2unix /testsuite/docker-entrypoint.sh && apt-get --purge remove -y dos2unix
# Define ENTRYPOINT
RUN ["chmod", "+x", "/testsuite/docker-entrypoint.sh"]
ENTRYPOINT ["sh", "/testsuite/docker-entrypoint.sh"] 
In docker-entrypoint.sh file
#!/bin/bash
pytest -v

$@

0 个答案:

没有答案