pytest+request+allure+excel接口自动化搭建 从0到1【四 Allure测试报告】

本文档介绍了如何在Mac环境下安装和使用Allure报告,包括安装Python相关依赖、配置环境变量以及通过pytest生成和查看报告。此外,还详细讲解了如何自定义Allure报告的样式,如修改输出格式、解决排版问题以及更改Logo和名称。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


pytese支持allure报告的使用,allure报告美观实用。

安装Allure报告

依赖环境:
java version “1.8.0_212”(依赖java环境需要安装jdk)
pytest == 6.1.0
allure-pytest == 2.8.18

Mac下安装allure环境

allure解压包下载

java jdk win版本下载

java jdk mac版本下载

配置allure环境

#命令行输入:
open -t ~/.bash_profile		#打开配置文件
export PATH=${PATH}:/Users/songpeilun/Downloads/allure-2.13.0/bin	#输入allure bin目录下的全路径
source ~/.bash_profile		#保存使命令生效

在这里插入图片描述

#查看是否安装成功
allure --version 或 allure
pip3 list

在这里插入图片描述

allure使用

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/7/21 16:13
# @Name    : peilun
# @File    : pytest_allure.py
# @Software: PyCharm
import pytest
import allure
import os

@pytest.fixture(scope='function')
def login():
    print("登录")
    yield
    print("登录完成")

@allure.feature('加入购物车')
def test_1(login):
    '''将苹果加入购物车'''
    print("测试用例1")

@allure.feature('加入购物车')
def test_2():
    '''将橘子加入购物车'''
    print("测试用例2")
命令行执行: 
pytest pytest_allure.py --alluredir ./reports   // 当前目录下生成report报告目录文件
allure serve reports		// 本地执行并打开报告

在这里插入图片描述
代码中运行 后面加上以下代码

if __name__ == '__main__':
    os.system("rm -rf  ./reports")		# 运行之前删除上次的报告目录
    pytest.main(["-s", "run.py",'--alluredir', './reports'])
    #os.system('allure generate ../reports -o ./allure-report --clean-alluredir')	#该步骤主要是生成本地的报告 然后手动打开报告(获取报告成功数量)
    os.system("allure serve ./reports")	# 启动本地服务,自动打开报告

在这里插入图片描述

在这里插入图片描述

自定义Allure报告样式

修改报告输出格式

在这里插入图片描述

    # 将allure报告结果json化
    allure.attach(con.host+data['Url'], '请求URL', allure.attachment_type.JSON)
    allure.attach(json.dumps(dicher), '请求头-Header', allure.attachment_type.JSON)
    allure.attach(json.dumps(diccase),'请求体-Body',allure.attachment_type.JSON)

在这里插入图片描述

修改报告格式排版乱的问题

在这里插入图片描述
在这里插入图片描述
需要在Python的安装目录修改

  1. python安装目录:E:\Python3.7\Lib\site-packages\allure_pytest
  2. 打开文件找到第95行,然后将内容清空
    在这里插入图片描述
    在这里插入图片描述

自定义修改logo和名称

需要在allure解压目录下安装

  1. allure解压目录:E:\allure-2.13.0\plugins\custom-logo-plugin\static
  2. 替换掉之前的logo文件
  3. 编辑styles.css文件
.side-nav__brand {
background: url('custom-logo.png') no-repeat left center !important;
margin-left: 10px;
height: 50px;
background-size: contain !important;
}


.side-nav__brand span{
display: none;
}

.side-nav__brand:after {
    content: "管家2.0";
    margin-left: 20px;
    font-size: 20px;
    height: 50px;
    line-height: 50px;
}
  1. 最后在allure.yml文件添加 - custom-logo-plugin
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Song_Lun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值