pytest+allure自动生成html漂亮报告

本机环境:
Python3.7.3
pytest 7.2.2
1、CMD上安装python的allure插件:

pip install  allure-pytest  -i https://mirrors.aliyun.com/pypi/simple

本机环境有点问题,需要在项目的venv\Lib\site-packages的库上安装此插件:
pip install --target=E:\py_project\pytest001\venv\Lib\site-packages allure-pytest -i https://mirrors.aliyun.com/pypi/simple

2、安装allure工具和配置系统环境:
allure是一个命令行工具,去官网上下载最新版本的zip包:https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/
在这里插入图片描述
下载完后,解压zip包,把bin目录添加到环境变量Path下。配置系统变量后,在cmd或pycharm控制台上输入:

C:\Users\Anthony\Desktop>allure --version
2.10.0

有版本号表示配置成功

3、使用一个Pytest脚本,跑用例之前先配置一个pytest.ini配置文件,把allure的配置写上addopts,并在主运行文件中main函数增加对应的内容:

[pytest]
addopts = -v -s --html=./report/report.html   --alluredir ./report/result --clean-alluredir
testpaths = ./testcases
python_files = test_*.py
python_classes = Test*
python_functions = test_*

在这里插入图片描述
主运行文件:

import pytest
import os

if __name__=="__main__":
    pytest.main(["-s","./","--capture=sys"])   #--capture=sys会把报错的情况写进测试报告中
    os.system('allure generate report/result -o report/allure_html --clean')

allure generate ./temps –o ./report --clean
参数说明:
./temp 临时的json格式报告的路径
-o 输出output
./report 生成的allure报告的路径
–clean 清空./report路径原来的报告
在这里插入图片描述
注意:主文件中report/result一定要与与pytest.ini文件的addopts的目录一样。此目录是自己设置存放报告的目录
在这里插入图片描述
4、配置完成后,运行一下主文件,跑完用例,就会自动生成allure的html报表:
报表路径:
在这里插入图片描述

在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值