Jenkins生成allure特色报告
一、插件安装
如下图所示,搜索插件allure安装。
二、插件配置
2.1 Jenkins的allure配置
①自行到网上下载allure客户端,②Jenkins进入Dashboard>>Manage Jenkins>>Global Tool Configuration.如图配置
2.2 在job中allure报告的配置
三、报告展示
3.1 代码示例
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 2022/10/6 9:06
# Author : root
# File : pytest_report.py
import os
import shutil
import pytest,allure,requests
import re
import io
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') #防止输出乱码
@allure.feature("weather interfaces test report")
class TestWeather(object):
def fun(self,data):
z = data.replace("\n", "").split(";")
data = {}
for i in z:
y = i.split("=")
try:
key = re.findall('data\["(.*?)"\]', y[0])[0]
value = eval(y[1])
data[key] = value
except:
pass
return data
@allure.step("天气接口断言")
@allure.title("天气接口断言")
@allure.story("天气接口测试")
@allure.description("验证天气接口是否良好")
@pytest.mark.parametrize(("city",),[("重庆",),("北京",),("上海",)])
def test_01(self,city):
url = "https://weathernew.pae.baidu.com/weathernew/pc"
params = {"query":city+"天气","srcid":4982}
res = requests.get(url,params=params).content.decode("unicode_escape")
data = re.findall('data\["position"\]=[\s\S]*false;',res)[0]
data = self.fun(data)
#print(data)
get_city = data["position"]["city"]
assert get_city == city
print(f"城市:{data['position']['city']}\n"
f"体感信息:{data['weather']['bodytemp_info']}\n"
f"风向:{data['weather']['wind_direction']}\n"
f"天气:{data['weather']['weather']}\n"
f"最低温:{data['weather']['dew_temperature']}度\n"
f"是否下雪:{data['weather']['precipitation_type']}\n"
f"风速:{data['weather']['wind_direction_num']}级\n"
f"最高温:{data['weather']['temperature']}\n"
f"风力等级:{data['weather']['wind_power']}\n"
)
if __name__ == '__main__':
report_path = r"./report"
temp_path = report_path + "//allure-results"
xml = report_path+"xml"
report_path_report = report_path + "\\report"
pytest.main(["pytest_report.py", "-s", f"--alluredir={temp_path}",
f"--junitxml={xml}/result.xml"])
城市:重庆 体感信息:湿度大,体感湿凉 风向:西北风 天气:阴 最低温:13度 是否下雪:无降雨和降雪 风速:7级 最高温:16 风力等级:3级
城市:北京 体感信息:人体感觉天气较凉 风向:西南风 天气:晴 最低温:-2度 是否下雪:无降雨和降雪 风速:5级 最高温:17
风力等级:3级
城市:上海 体感信息:湿度大,体感湿凉 风向:西北风 天气:阴 最低温:15度 是否下雪:无降雨和降雪 风速:7级 最高温:18
风力等级:1级
3.2 在Jenkins中运行成功后展示
3.3 allure报告展示
可以查看历史和重试次数以及总览