首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pytest在Docker容器中生成html?

Pytest在Docker容器中生成html?
EN

Stack Overflow用户
提问于 2021-03-29 23:52:07
回答 1查看 210关注 0票数 0

我正在尝试开发一个用于web自动化测试的应用程序,它可以生成一个html报告。它在本地工作,但当试图将其停靠时,我遇到了麻烦。

这是dockerfile中最重要的一行(我认为)

代码语言:javascript
复制
CMD ["pytest", "--html=report.html", "tests/test_your_info_page.py"]

最终目标是在创建容器时开始测试。但是'report.html‘文件似乎没有生成

docker文件的其余部分如下所示

代码语言:javascript
复制
FROM python:3.9 AS webautomation

# install google chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get -y update
RUN apt-get install -y google-chrome-stable

# install chromedriver
RUN apt-get install -yqq unzip
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/

# set display port to avoid crash
ENV DISPLAY=:99

COPY requirements.txt .

RUN pip install -r requirements.txt

WORKDIR .
COPY . .

CMD ["pytest", "--html=report.html", "tests/test_your_info_page.py"]

FROM nginx:alpine

COPY --from=webautomation . /usr/share/nginx/html

requirements.txt看起来像是

代码语言:javascript
复制
pytest==6.2.2
selenium==3.141.0
pytest-html==3.1.1

项目结构

代码语言:javascript
复制
-tests
      -test_your_info_page.py
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-30 22:50:15

问题似乎与多阶段构建有关。删除FROM nginx后,我现在可以在docker容器中运行pytest了。

更新

使用docker cp命令,我可以复制在本地计算机上生成的报告并在浏览器中查看它

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66857397

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档