声明:参考B站视频,自学成长记录
https://www.bilibili.com/video/BV1u5411A7Um?p=12
什么是allure
pytest-html 生成html格式得测试报告
allure-pytest 生成 更美观 得测试报告
下载、配置allure
下载allure
下载地址:
https://github.com/allure-framework/allure2/releases
解压allure
配置path
将allure的路径配置到path环境变量中
验证allure
1、重启pycharm
2、Terminal窗口:allure --version 进行验证
如下图,则表示配置成功
安装allure-pytest插件
pycharm --> File --> Settings
Project --> Python Interpreter --> +
检索 allure-pytest --> Install Package
allure-pytest插件未安装,执行pytest时会报:
error: unrecognized arguments: --alluredir
生成allure报告
增加参数
pytest.ini 增加 –alluredir ./tmp 参数,生成json临时文件
[pytest]
addopts = -vs --alluredir ./temp
python_files = test_*.py *_test.py
python_classes = Test*
python_functions = test_*
testpaths = ./testcase
markers =
smoke:冒烟测试
uat:业务测试
运行脚本
运行结果
在项目根目录 自动生成 temp文件 + 对应json文件
将json文件生成html文件
执行文件中增加:
import os
os.system(‘allure generate ./temp -o ./reports --clean’)
# -*- coding: utf-8 -*-
# @File : pytest-run.py
import os
import pytest
if __name__ == '__main__':
pytest.main()
os.system('allure generate ./temp -o ./reports --clean')
'''
allure generate:生成命令
./temp: 原json文件目录
-o: 输出
./reports: 新生成的allure的报告
--clean: 每次生成时 会清空之前./reports生成的报告
'''
查看reports/index.html
allure报告效果