Allure报告的使用
pytese支持allure报告的使用,allure报告美观实用。
安装Allure报告
依赖环境:
java version “1.8.0_212″(依赖java环境需要安装jdk)
pytest == 6.1.0
allure-pytest == 2.8.18
Mac下安装allure环境
allure解压包下载
配置allure环境
open -t ~/.bash_profile
export PATH=${PATH}:/Users/songpeilun/Downloads/allure-2.13.0/bin
source ~/.bash_profile
allure --version 或 allure
pip3 list
allure使用
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 serve ./reports")
自定义Allure报告样式
修改报告输出格式
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的安装目录修改
- python安装目录: E:\Python3.7\Lib\site-packages\allure_pytest
- 打开文件找到第95行,然后将内容清空
; 自定义修改logo和名称
需要在allure解压目录下安装
- allure解压目录: E:\allure-2.13.0\plugins\custom-logo-plugin\static
- 替换掉之前的logo文件
- 编辑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;
}
- 最后在allure.yml文件添加 – custom-logo-plugin
Original: https://blog.csdn.net/Song_Lun/article/details/120547084
Author: Song_Lun
Title: pytest+request+allure+excel接口自动化搭建 从0到1【四 Allure测试报告】
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/775496/
转载文章受原作者版权保护。转载请注明原作者出处!