最专业的网站建设推广,西安网站建设专业,大学生活网站设计,个人网页设计作品介绍Allure简介 Allure是一款非常轻量级并且非常灵活的开源测试报告生成框架。 它支持绝大多数测试框架#xff0c; 例如TestNG、Pytest、JUint等。它简单易用#xff0c;易于集成。下面就Pytest如何与Allure集成做详细介绍。
Pytest框架集成Allure Pytest是Python的单元测试框架…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 1def test2(self):assert 11
if __name____main__:#生成测试报告jsonpytest.main([-s, -q, --alluredir, report/result, test01.py])#将测试报告转为html格式splitallure generate ./report/result -o ./report/html --cleanos.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 --cleanProcess 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(https://www.baidu.com/)#添加权限对应链接allure.testcase(https://www.baidu.com/)#添加用例对应链接def test_login(self):这里是登录成功测试用例:return:assert 1 1allure.severity(critical)def test_01(self):assert 11allure.severity(normal)def test_02(self):assert 11allure.severity(minor)def test_03(self):assert 11allure.severity(trivial)def test_04(self):assert 11if __name____main__:#生成测试报告jsonpytest.main([-s, -q, --alluredir, report/result, test01.py])#将测试报告转为html格式splitallure generate ./report/result -o ./report/html --cleanos.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
.....
5 passed in 0.09s
Report successfully generated to .\report\html
allure generate ./report/result -o ./report/html --cleanProcess finished with exit code 0 三、Severity定制标记用例级别详解
根据测试用例的重要性划分测试用例等级如果没指定等级默认为normal级别
Allure中对严重级别的定义 1、 Blocker级别中断缺陷客户端程序无响应无法执行下一步操作
allure.severity(blocker)
2、 Critical级别临界缺陷 功能点缺失
allure.severity(critical)
3、 Normal级别普通缺陷数值计算错误
allure.severity(normal)
4、 Minor级别次要缺陷界面错误与UI需求不符
allure.severity(minor)
5、 Trivial级别轻微缺陷必输项无提示或者提示不规范
allure.severity(trivial)
import pytest,os
import allure
class Test(object):allure.feature(登录功能)allure.story(登录成功)allure.severity(blocker)def test_login(self):这里是登录成功测试用例:return:assert 1 1allure.severity(critical)def test_01(self):assert 11allure.severity(normal)def test_02(self):assert 11allure.severity(minor)def test_03(self):assert 11allure.severity(trivial)def test_04(self):assert 11if __name____main__:#生成测试报告jsonpytest.main([-s, -q, --alluredir, report/result, test01.py])#将测试报告转为html格式splitallure generate ./report/result -o ./report/html --cleanos.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
.....
5 passed in 0.10s
Report successfully generated to .\report\html
allure generate ./report/result -o ./report/html --cleanProcess finished with exit code 0四、Step和attach定制详解
allure.step(调用登录): # 将一个测试用例分成几个步骤将步骤打印到测试报告中
allure.attach(账号, 18221124104) # attach可以打印一些附加信息
import pytest,os
import allureallure.feature(购物车功能) # feature定义功能
class Test(object):allure.story(加入购物车) # story定义用户场景def test_add_shopping_trolley(self):login(橙子, 登录密码) # 调用“步骤函数”with allure.step(浏览商品): # 将一个测试用例分成几个步骤将步骤打印到测试报告中步骤2allure.attach(商品1, NIKE球鞋) # attach可以打印一些附加信息allure.attach(商品2, 大众速腾)with allure.step(点击商品): # 将一个测试用例分成几个步骤将步骤打印到测试报告中步骤3passwith allure.step(校验结果):allure.attach(期望结果, 添加购物车成功)allure.attach(实际结果, 添加购物车失败)assert success failedallure.story(修改购物车)def test_edit_shopping_trolley(self):passpytest.mark.skipif(reason本次不执行)allure.story(删除购物车)def test_delete_shopping_trolley(self):passallure.step(账号登录) # 还可以将一个函数作为一个步骤调用此函数时报告中输出一个步骤步骤名字通常是函数名我把这样的函数叫“步骤函数”
def login(user, pwd):print(user, pwd)
if __name____main__:#生成测试报告jsonpytest.main([-s, -q, --alluredir, report/result, test01.py])#将测试报告转为html格式splitallure generate ./report/result -o ./report/html --cleanos.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
橙子 登录密码
F.sFAILURES
_______________________ Test.test_add_shopping_trolley ________________________self test.test01.Test object at 0x0000024F3425C898allure.story(加入购物车) # story定义用户场景def test_add_shopping_trolley(self):login(橙子, 登录密码) # 调用“步骤函数”with allure.step(浏览商品): # 将一个测试用例分成几个步骤将步骤打印到测试报告中步骤2allure.attach(商品1, NIKE球鞋) # attach可以打印一些附加信息allure.attach(商品2, 大众速腾)with allure.step(点击商品): # 将一个测试用例分成几个步骤将步骤打印到测试报告中步骤3passwith allure.step(校验结果):allure.attach(期望结果, 添加购物车成功)allure.attach(实际结果, 添加购物车失败)assert success failed
E AssertionErrortest01.py:51: AssertionError
1 failed, 1 passed, 1 skipped in 0.18s
Report successfully generated to .\report\html
allure generate ./report/result -o ./report/html --cleanProcess finished with exit code 0五、Issue缺陷链接和TestCase用例链接定制详解
allure.issue() 缺陷 对应缺陷管理系统里面的链接在测试报告中可以点击跳转的
allure.testcase() 测试用例的链接地址 对应功能测试用例系统里面的case链接在测试报告中可以点击跳转的
import pytest,os
import allure
class Test(object):allure.feature(登录功能)allure.story(登录成功)allure.severity(blocker)allure.issue(https://www.baidu.com/)#添加缺陷对应链接allure.testcase(https://www.baidu.com/)#添加用例对应链接def test_login(self):这里是登录成功测试用例:return:assert 1 1allure.severity(critical)def test_01(self):assert 11allure.severity(normal)def test_02(self):assert 11allure.severity(minor)def test_03(self):assert 11allure.severity(trivial)def test_04(self):assert 11if __name____main__:#生成测试报告jsonpytest.main([-s, -q, --alluredir, report/result, test01.py])#将测试报告转为html格式splitallure generate ./report/result -o ./report/html --cleanos.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
.....
5 passed in 0.05s
Report successfully generated to .\report\html
allure generate ./report/result -o ./report/html --cleanProcess finished with exit code 0五、link链接定制详解
allure.link(‘https://www.baidu.com/’)
六、attachment附件制定
allure.attachment()