Pytest配合Allure生成测试报告

本文主要是介绍如何将测试报告生成工具Allure集成到pytest中

1、首先需要安装pytest

pip install pytest

2、然后安装pytest-allure-adaptor,pytest-allure-adaptor是pytest的一个插件,通过它我们可以生成Allure所需要的用于生成测试报告的数据

pip install pytest-allure-adaptor

3、执行测试生成Allure报告所需要的测试结果数据。在pytest执行测试的时候,指定–alluredir参数及测试数据保存的目录即可

pytest 测试文件所在路径 --alluredir 生成的测试结果数据保存的目录

例如pytest /Users/chenwenbin/PycharmProjects/InterfaceTest --alluredir /Users/chenwenbin/PycharmProjects/InterfaceTest/allure-result
如果是在项目所在路径下执行命令,则无需在pytest命令后指定测试文件所在路径
执行完以上命令之后会在指定的测试结果数据保存的目录下生成一个xml文件,后期allure报告就是根据这里的数据来生成的

  • 安装Allure
brew install allure

4、生成测试报告,将前提步骤中的xml文件生成报告保存在指定目录下

allure generate 测试结果数据所在目录 -o 测试报告保存的目录 --clean

–clean目的是先清空测试报告目录,再生成新的测试报告

  • 打开报告
    1.可以在pycharm中找到保存的报告中的html文件,右键选择open in browser
    2.或者在终端输入
allure open -h 127.0.0.1 -p 8083 /Users/chenwenbin/PycharmProjects/InterfaceTest/allure-result/html

/Users/chenwenbin/PycharmProjects/InterfaceTest/allure-result/html是我存放报告html文件所在的目录

####注意啦!如果生成xml的时候提示下面这个东西
image.png
解决办法如下
image.png
image.png

猜你喜欢

转载自blog.csdn.net/muskjp/article/details/108124857