Allure简介
Allure是一款非常轻量级并且非常灵活的开源测试报告生成框架。 它支持绝大多数测试框架, 例如TestNG、Pytest、JUint等。它简单易用,易于集成。下面就Pytest如何与Allure集成做详细介绍。
Pytest框架集成Allure
Pytest是Python的单元测试框架,非常方便和易用。强烈推荐对于用Python进行测试工作的小伙伴使用这个测试框架,相比与Python自带的UnitTest好用太多太多。今天我们主要是介绍如何将测试报告生成工具Allure集成到Pytest中。目前现在已经有allure2了,我们要使用的就是这个allure2
一、Features、Story定制详解
@allure.feature # 用于定义被测试的功能,被测产品的需求点,模块
@allure.story # 用于定义被测功能的用户场景,即子功能点,用例
import pytest,os
import allure
class Test(object):
@allure.feature('登录功能')
@allure.story('登录成功')
def test_login(self):
assert 1 == 1
def test2(self):
assert 1==1
if __name__=="__main__":
#生成测试报告json
pytest.main(["-s", "-q", '--alluredir', 'report/result', 'test01.py'])
#将测试报告转为html格式
split='allure '+'generate '+'./report/result '+'-o '+'./report/html '+'--clean'
os.system('cd C:/Users/wangli/PycharmProjects/Test/test/report')
os.system(split)
print(split)
"C:\Program Files\Python35\python.exe" C:/Users/wangli/PycharmProjects/Test/test/test01.py
..
2 passed in 0.06s
Report successfully generated to .\report\html
allure generate ./report/result -o ./report/html --clean
Process finished with exit code 0
二、title用例标题和description用例描述定制详解
@allure.title(用例的标题)
@allure.description(用例的描述)
或用例描述也可写成这样
""" 这里是登录成功测试用例 """
import pytest,os
import allure
class Test(object):
@allure.feature('登录功能')
@allure.story('登录成功')
@allure.title('用例的标题')#用例的标题
@allure.severity('blocker')
@allure.issue(&#