allure相关参数解释以及代码示例

 1 # coding:utf-8
 2 
 3 import pytest
 4 import allure
 5 
 6 
 7 # 测试函数
 8 @allure.step("字符串相加:{0},{1}")     # 测试步骤,可通过format机制自动获取函数参数
 9 def str_add(str1, str2):
10     print "hello"
11     if not isinstance(str1, str):
12         return "%s is not a string" % str1
13     if not isinstance(str2, str):
14         return "%s is not a string" % str2
15     return str1 + str2
16 
17 
18 @allure.severity("critical")               # 优先级,包含blocker, critical, normal, minor, trivial 几个不同的等级
19 @allure.feature("测试模块_demo1")           # 功能块,feature功能分块时比story大,即同时存在feature和story时,feature为父节点
20 @allure.story("测试模块_demo2")             # 功能块,具有相同feature或story的用例将规整到相同模块下,执行时可用于筛选
21 @allure.issue("BUG号:123")                 # 问题表识,关联标识已有的问题,可为一个url链接地址
22 @allure.testcase("用例名:测试字符串相等")      # 用例标识,关联标识用例,可为一个url链接地址
23 @pytest.mark.parametrize("para_one, para_two",              # 用例参数
24                          [("hello world", "hello world"),   # 用例参数的参数化数据
25                           (4, 4),
26                           ("中文", "中文")],
27                          ids=["test ASCII string",          # 对应用例参数化数据的用例名
28                               "test digital string",
29                               "test unicode string"])
30 def test_case_example(para_one, para_two):
31     """用例描述:测试字符串相等
32     :param para_one: 参数1
33     :param para_two: 参数2
34     """
35 
36     # 获取参数
37     paras = vars()
38     # 报告中的环境参数,可用于必要环境参数的说明,相同的参数以后者为准
39     allure.environment(host="172.6.12.27", test_vars=paras)
40     # 关联的资料信息, 可在报告中记录保存必要的相关信息
41     allure.attach("用例参数", "{0}".format(paras))
42     # 调用测试函数
43     res = str_add(para_one, para_two)
44     # 对必要的测试中间结果数据做备份
45     allure.attach("str_add返回结果", "{0}".format(res))
46     # 测试步骤,对必要的测试过程加以说明
47     with pytest.allure.step("测试步骤2,结果校验 {0} == {1}".format(res, para_one+para_two)):
48         assert res == para_one+para_two, res
49 
50 
51 if __name__ == '__main__':
52     # 执行,指定执行测试模块_demo1, 测试模块_demo2两个模块,同时指定执行的用例优先级为critical,blocker
53     pytest.main(['--allure_stories=测试模块_demo1, 测试模块_demo2', '--allure_severities=critical, blocker'])

猜你喜欢

转载自www.cnblogs.com/guozhijia/p/12632382.html