Pytest框架+Allure报告
简介:
Allure Framework是一种灵活的轻量级多语言测试报告工具,不仅可以以简洁的网络报告形式非常简洁地显示已测试的内容,而且还允许参与开发过程的每个人从日常执行中提取最大程度的有用信息。
安装库:
pip install pytest
pip install allure-pytest
pip install pytest-allure-adaptor
allure是一个命令行工具,需要去github上下载最新版 :https://github.com/allure-framework/allure2/releases
下载完成之后,解压到本地电脑;把bin目录添加到环境变量Path下。
示例:
import allure
import pytest
import os
@allure.step("操作步骤1的描述")
def setp1():
print('操作步骤1')
@allure.step("操作步骤2的描述")
def setp2():
print('操作步骤2')
@allure.feature('测试接口--模块描述')
class Test_01(object):
@allure.story('测试用例的描述--测试用例1')
def test_01(self, first):
'''
用例详情描述
:param first: 前置条件
:return:
'''
setp1()
setp2()
print('test_01,调用first成功', first)
assert 1 == 1
@allure.story('测试用例的描述--测试用例2')
def test_02(self):
print('test_02,不需要调用')
@allure.story('测试用例的描述--测试用例3')
def test_03(self, first2):
print('test_03,调用first成功', first2)
#生成测试报告数据
pytest.main(['allureTest.py','--alluredir','./report/allure_raw'])
#测试报告在线预览-浏览器访问(使用火狐/谷歌--设置默认浏览器)
os.system('allure serve ./report/allure_raw')
#生成本地测试报告静态数据页面(可手动对index.html用浏览器打开查看)
os.system('allure generate ./report/allure_raw/ -o ./report/html/ --clean')
生成测试报告:
Allure相关的内容