本文链接:https://blog.csdn.net/wust_lh/article/details/86685912
目录
一、安装Allure
1、Allure2.7.0下载
2、解压
3、环境变量配置
4、检查是否安装成功:
二、安装allure-pytest
三、安装pytest-html
四、实例代码
五、生成html报告
1、运行命令
2、生成html报告命令
3、成功测试结果
4、失败测试结果:
5、成功和失败测试对应的代码:
6、查看html报告
六、Jenkins集成Allure插件
1、安装Allure Jenkins Plugin插件
2、配置Allure Commandline
3、配置
4、html报告
七、Jenkins发送邮件配置
Allure Pytest Adaptor是Pytest的一个插件,通过它我们可以生成Allure所需要的用于生成测试报告的数据。
前提:配置好Java环境,安装好pytest,可参考:https://blog.csdn.net/wust_lh/article/details/86545697
写在最前:由于pytest-allure-adaptor版本原因,导致安装配置好后程序一直报错,如图所示错误,尝试了好多类似的方法均没有解决,很是苦恼。后来想到受https://www.kancloud.cn/guanfuchang/python_selenium/714653启发,想到可能是allure版本原因造成的,于是将安装命令改为:pip install allure-pytest,安装成功后发现问题解决了。
本文认为:网上目前大多教程使用命令:pip install pytest-allure-adaptor是针对allure1的版本安装的,针对allure2安装则使用pip install allure-pytest。
一、安装Allure
1、Allure2.7.0下载
下载地址:https://github.com/allure-framework/allure2/releases/tag/2.7.0
2、解压
将下载的压缩包解压:
3、环境变量配置
在变量PATH中添加bin目录的路径,如本文压缩包解压路径:D:\soft\allure-2.7.0\bin
4、检查是否安装成功:
查看安装版本命令:allure --version
二、安装allure-pytest
1、安装命令:pip install allure-pytest
2、安装pyyaml:pip install pyyaml,在python代码中,import allure会出错,需安装pyyaml
三、安装pytest-html
安装命令:pip install pytest-html
四、实例代码
test_feature.py
# -*- coding: utf-8 -*-
# @File : test_case.py
import allure
import pytest
@allure.feature('test_module_01')
def test_case_01():
"""
用例描述:Test case 01
"""
assert 0 == 0
@allure.feature('test_module_02')
def test_case_02():
"""
用例描述:Test case 02
"""
assert 0 == 0
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './report/xml'])
五、生成html报告
1、运行命令
pytest D:\workspaces\python\allurePython\test_feature.py --alluredir=./allure-results/
2、生成html报告命令
allure generate report/ -o allure-reports/
3、成功测试结果
4、失败测试结果:
5、成功和失败测试对应的代码:
此时,可以看到,在allurePython目录下多了两个文件夹,allure-reports目录下为生成的allure的html报告
6、查看html报告
六、Jenkins集成Allure插件
1、安装Allure Jenkins Plugin插件
2、配置Allure Commandline
勾选自动安装,配置好name和版本号
3、配置
还是以“四、实例代码”为例,配置构建操作和构建后操作
4、html报告
同“五、生成html”中的报告
七、Jenkins发送邮件配置
配置方法参考:https://blog.csdn.net/wust_lh/article/details/86573797
(1)将Default Content改为:
$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS:
Check console output at ${BUILD_URL}allure/ to view the results.
(2)Attach Buile Log
完成配置后立即构建,邮箱中会收到构建完成后的邮件,并将构建日志作为附件发送。
至此,使用Pytest+Allure的全过程完成。
————————————————
版权声明:本文为CSDN博主「wust_lh」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wust_lh/article/details/86685912