广州好的网站建设,三桥做网站,wordpress英语商城插件,设计师能做网站前端吗背景
最近想做一个简单的pytest 测试#xff0c;用allure出报告#xff0c;结果发现网上的方法都是在windows上装jenkins,然后用jenkins跑一个本地的运行环境。这种做法明显很不2019年。于是我决定做一个在jenkins上使用docker运行pytest#xff0c;然后再出allure报告的文…背景
最近想做一个简单的pytest 测试用allure出报告结果发现网上的方法都是在windows上装jenkins,然后用jenkins跑一个本地的运行环境。这种做法明显很不2019年。于是我决定做一个在jenkins上使用docker运行pytest然后再出allure报告的文章。
思路
在一台电脑上安装jenkins,可以参考我的文章https://www.yinyubo.cn/?p268准备python代码放到git上jenkins通过git拉取代码。代码中包含Dockerfile,测试用例,requirements.txt拉取代码之后通过Dockerfile产生一个python的镜像并且在镜像中通过requirements.txt去安装pytest,allure的相关依赖通过这个镜像产生一个容器容器命令运行pytest产生测试报告并且挂载到jenkins服务器上.(注意这里为什么要在容器里运行pytest呢因为如果在Dockerfile里运行pytest一旦产生测试失败是会导致jenkins退出shell执行的)Jenkins通过allure插件读取第4步产生的测试报告。生成allure报告
具体步骤
第一步忽略。请参考文章https://www.yinyubo.cn/?p268准备python代码。产生Dockerfile,测试用例,requirements.txt如下图Dockerfile内容如下 1 2 3 4 5 FROM python:3.7.3 WORKDIR . ADD . . RUN pip install -r requirements.txt CMD [pytest, -q,TestCase/AIMP/Connect/AIMP_Connect_01.py,--alluredir,allure-results]
requirements.txt内容如下 1 2 3 4 5 6 7 8 9 10 allure-pytest2.6.2 allure-python-commons2.6.2 atomicwrites1.3.0 attrs19.1.0 colorama0.4.1 more-itertools7.0.0 pluggy0.9.0 py1.8.0 pytest4.4.1 six1.12.0
测试用例可以如下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 import pytest def test_success(): this test succeeds print(1) assert True def test_failure(): print(2) this test fails assert False def test_skip(): print(3) this test is skipped pytest.skip(for a reason!) def test_broken(): raise Exception(oops) def test_success2(): print(4) assert True 3.jenkins配置这里如何拉取git代码就不写了。这个很简单主要是构建命令和构建后操作这里我复制了我的构建命令如下 1 2 3 nameapitest docker build -t $name . docker run -d --name $name -v $PWD/allure-results:/allure-results $name
效果如图 4.运行job查看allure结果 任何程序错误以及技术疑问或需要解答的请添加