1. 下载安装 Allure 下载最新版本:https://github.com/allure- framework/allure2/releases 
解压到非中文目录下 然后设置环境变量: 将allure/bin目录添加到path变量 重新打开cmd,运行allure --version 
安装allure-pytest插件 pip install allure-pytest
2.报告生成 创建项目或者包 创建脚本文件 例如:test-allure.py 修改运行方式为python运行
import pytest
import allure
import os
@pytest.fixture(scope='function')
def login():
print("登录")
yield
print("登录完成")
def test_cart(login):
"""将手机加入购物车"""
print("添加购物车1")
def test_cart1():
"""将电脑加入购物车"""
print("添加购物车2")
if __name__ == "__main__":
# 执行pytest单元测试,生成 Allure 报告需要的数据存在 /temp 目录
pytest.main(['--alluredir', './temp'])
# 执行命令 allure generate ./temp -o ./report --clean ,生成测试报告
os.system('allure generate ./temp -o ./report --clean')
运行test-allure.py,会自动化生成测试报告  打开测试报告 
|