pytest+allure生成美化报告

pytest可以生成junit格式的xml报告和HTML报告,命令如下:

pytest test_demo.py --junitxml=report.xml
pytest test_demo.py --html=report.html #需要安装插件:pip install pytest-html

然后在同目录下生成了report.html文件,打开如下:
image

界面看着不太美观,不过有第三方的Allure 报告更加灵活美观,下面我们来介绍allure使用

  1. allure包下载:https://github.com/allure-framework/allure2/releases

  2. 解压 -> 进入bin目录 -> 运行allure.bat,

  3. 把bin目录加入PATH环境变量
    image

  4. 安装 allure-pytest插件

pip install allure-pytest
  1. 生成报告
pytest [测试文件] -s -q --alluredir=./result #--alluredir用于指定存储测试结果的路径)
  1. 查看报告
    方式一:直接打开默认浏览器展示报告
allure serve ./result/

image

方式二:从结果生成报告

allure generate ./result/ -o ./report/ --clean   (覆盖路径加--clean) #生成报告
allure open -h 127.0.0.1 -p 8883 ./report/		#打开报告

效果是一样的就不展示图片了

posted @ 2022-06-01 10:57  Harry_666  阅读(141)  评论(0编辑  收藏  举报