pytest学习和使用25-当看到allure的动态生成标题和描述的特性时,直言简直太灵活了(allure.dynamic使用)
导读:1 之前关于标题和描述是怎么做的?1.1 之前标题使用@allure.title装饰器举个例子看下,之前已经学习过了,不再赘述了:# -*- coding:utf-8 -*- # 作者:虫无涯 # 日期:2023/3/28 # 文件名称:...
1 之前关于标题和描述是怎么做的?
1.1 之前标题使用@allure.title装饰器
- 举个例子看下,之前已经学习过了,不再赘述了:
# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/3/28
# 文件名称:test_allure_title.py
# 作用:@allure.title特性
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson
import allure
@allure.title("用户正常登陆")
def test_login01():
pass
@allure.title("用户名错误")
def test_login02():
pass
- 查看报告: 在这里插入图片描述
1.2 之前描述使用@allure.description装饰器
- 举例:
# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/3/28
# 文件名称:test_allure_description.py
# 作用:@allure.description特性
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson
import allure
import pytest
# 使用方法一
@allure.description("""
这个用例的主要所用是验证?
哦,对了,我也不知道干啥的!!!
""")
def test_case01():
num = 100 * (1 + 9)
assert num == 1000
# 使用方法二
def test_case02():
"""
这是一个用例!
这个用例什么也没做!
这个用例只是简单做个验证而已~
"""
pass
在这里插入图片描述2 allure.dynamic的动态功能怎么做?
2.1 allure.dynamic源码
class Dynamic(object):
@staticmethod
def title(test_title):
plugin_manager.hook.add_title(test_title=test_title)
@staticmethod
def description(test_description):
plugin_manager.hook.add_description(test_description=test_description)
@staticmethod
def description_html(test_description_html):
plugin_manager.hook.add_description_html(test_description_html=test_description_html)
@staticmethod
def label(label_type, *labels):
plugin_manager.hook.add_label(label_type=label_type, labels=labels)
@staticmethod
def severity(severity_level):
Dynamic.label(LabelType.SEVERITY, severity_level)
@staticmethod
def feature(*features):
Dynamic.label(LabelType.FEATURE, *features)
@staticmethod
def story(*stories):
Dynamic.label(LabelType.STORY, *stories)
@staticmethod
def tag(*tags):
Dynamic.label(LabelType.TAG, *tags)
@staticmethod
def link(url, link_type=LinkType.LINK, name=None):
plugin_manager.hook.add_link(url=url, link_type=link_type, name=name)
@staticmethod
def issue(url, name=None):
Dynamic.link(url, link_type=LinkType.ISSUE, name=name)
@staticmethod
def testcase(url, name=None):
Dynamic.link(url, link_type=LinkType.TEST_CASE, name=name)
2.2 从allure.dynamic源码可得出能动态设置的类型
allure.dynamic.title
allure.dynamic.description
allure.dynamic.description_html
allure.dynamic.label
allure.dynamic.severity
allure.dynamic.feature
allure.dynamic.story
allure.dynamic.tag
allure.dynamic.link
allure.dynamic.issue
allure.dynamic.testcase
2.3 类型说明和举例
2.3.1 allure.dynamic.title
- 动态标题:
@allure.title("使用装饰器标题")
def test_title():
print("CASE-01")
allure.dynamic.title("使用动态标题")
在这里插入图片描述2.3.2 allure.dynamic.description
- 动态描述:
@allure.description("使用装饰器进行描述")
def test_description():
print("CASE-02")
allure.dynamic.description("使用动态描述")
在这里插入图片描述2.3.3 allure.dynamic.description_html
- 动态描述传一段
html
代码:
html_d = """
h1>
Test @allure.description_html/h1>
table style="width:100%">
tr>
th>
姓名/th>
th>
成绩/th>
/tr>
tr align="center">
td>
张三/td>
td>
100/td>
/table>
"""
def test_description_html():
print("CASE-03")
allure.dynamic.description_html(html_d)
在这里插入图片描述2.3.4 allure.dynamic.label
- 动态用例的标签;
- 举例:
def test_label():
print("CASE-04")
allure.dynamic.label("this_label")
2.3.5 allure.dynamic.severity
- 动态用例的优先级;
- 举例:
@allure.severity("trivial")
def test_severity():
print("CASE-05")
allure.dynamic.severity("blocker")
在这里插入图片描述2.3.6 allure.dynamic.feature
- 模块名称 功能点的描述,往下是 story;
- 举例:
@allure.feature('feature000')
def test_feature():
print("CASE-06")
allure.dynamic.feature("feature111")
在这里插入图片描述2.3.7 allure.dynamic.story
- 用户故事,往下是title;
- 举例:
@allure.story('story222')
def test_story():
print("CASE-07")
allure.dynamic.story("story333")
在这里插入图片描述2.3.8 allure.dynamic.tag
- 用例的标记;
- 举例:
def test_tag():
print("CASE-08")
allure.dynamic.tag("this is tag")
在这里插入图片描述2.3.9 allure.dynamic.link
- 定义一个链接;
- 举例:
@allure.link("https://blog.csdn.net/NoamaNelson")
def test_link():
print("CASE-09")
allure.dynamic.link("https://juejin.cn/user/3655236621185246")
在这里插入图片描述2.3.10 allure.dynamic.issue
- 缺陷,对应缺陷管理系统里面的链接;
- 举例:
def test_issue():
print("CASE-10")
allure.dynamic.issue('https://bbs.csdn.net/forums/NoamaNelson', '全栈测试技术社区')
在这里插入图片描述2.3.11 allure.dynamic.testcase
- 测试用例的链接地址;
- 举例:
def test_testcase():
print("CASE-11")
allure.dynamic.issue("https://bbs.csdn.net/forums/NoamaNelson?category=10003&
typeId=1566629", "测试用例地址")
在这里插入图片描述3 本文涉及到的源码
# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/3/29
# 文件名称:test_allure_dynamic.py
# 作用:allure.dynamic特性使用
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson
import allure
@allure.title("使用装饰器标题")
def test_title():
print("CASE-01")
allure.dynamic.title("使用动态标题")
@allure.description("使用装饰器进行描述")
def test_description():
print("CASE-02")
allure.dynamic.description("使用动态描述")
html_d = """
h1>
Test @allure.description_html/h1>
table style="width:100%">
tr>
th>
姓名/th>
th>
成绩/th>
/tr>
tr align="center">
td>
张三/td>
td>
100/td>
/table>
"""
def test_description_html():
print("CASE-03")
allure.dynamic.description_html(html_d)
def test_label():
print("CASE-04")
allure.dynamic.label("this_label")
@allure.severity("trivial")
def test_severity():
print("CASE-05")
allure.dynamic.severity("blocker")
@allure.feature('feature000')
def test_feature():
print("CASE-06")
allure.dynamic.feature("feature111")
@allure.story('story222')
def test_story():
print("CASE-07")
allure.dynamic.story("story333")
def test_tag():
print("CASE-08")
allure.dynamic.tag("this is tag")
@allure.link("https://blog.csdn.net/NoamaNelson")
def test_link():
print("CASE-09")
allure.dynamic.link("https://juejin.cn/user/3655236621185246")
def test_issue():
print("CASE-10")
allure.dynamic.issue('https://bbs.csdn.net/forums/NoamaNelson', '全栈测试技术社区')
def test_testcase():
print("CASE-11")
allure.dynamic.issue("https://bbs.csdn.net/forums/NoamaNelson?category=10003&
typeId=1566629", "测试用例地址")
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: pytest学习和使用25-当看到allure的动态生成标题和描述的特性时,直言简直太灵活了(allure.dynamic使用)
本文地址: https://pptw.com/jishu/3384.html