微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Pytest结合Allure生成测试报告

import pytest
import os
import allure

@allure.feature("订单测试集一级目录")
class TestOrder:

def setup_class(self):
print("执行测试类之前,我需要执行......")


@allure.story("订单二级模块")
@allure.title("标题1")
def test_Order001(self):
assert 1 + 1 == 2

@allure.title("标题2")
def test_Order002(self):
assert 2 + 1 == 4

@allure.title("标题3")
@pytest.mark.parametrize("a,b",[(1,2)]) #数据驱动
def test_Info(self,a,b):
assert b == a + 1

def teardown_class(self):
print("执行测试类之后,我需要执行......")




if __name__ == '__main__':
pytest.main(['test_OrderList.py','--alluredir','../report/tmp']) #生成报告需要的源文件
#方法一:不会自动打开测试报告
os.system("allure generate ../report/tmp -o ../report/report --clean") #生成测试报告,-o表示:输出,../report/tmp表示源文件目录,../report/report表示生成报告的位置

#方法二:执行完成会自动打开测试报告(推荐)
os.system("allure serve ../report/report)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐