如果你还想从头学起Pytest,可以看看这个系列的文章哦!
https://www.cnblogs.com/poloyy/category/1690628.html
前言
- @allure.title 和 @allure.description 都是装饰器,给测试用例提供标题和描述
- 其实 allure 还提供了在测试用例执行过程中动态指定标题和描述等标签的方法
- 如: allure.dynamic.description allure.dynamic.title
allure.dynamic 的源代码
class Dynamic(object): @staticmethod def title(test_title): plugin_manager.hook.add_title(test_title=test_title) @staticmethod description(test_description): plugin_manager.hook.add_description(test_description=test_description) @staticmethod 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 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,1)">stories) @staticmethod def tag(*tags): Dynamic.label(LabelType.TAG,1)">tags) @staticmethod def link(url,link_type=LinkType.LINK,name=None): plugin_manager.hook.add_link(url=url,link_type=link_type,1)">name) @staticmethod def issue(url,1)">None): Dynamic.link(url,link_type=LinkType.ISSUE,1)">def testcase(url,link_type=LinkType.TEST_CASE,name=name)
重点
allure.dynamic.feature
allure.dynamic.link
allure.dynamic.issue
allure.dynamic.testcase
allure.dynamic.story
allure.dynamic.title
allure.dynamic.description
title 的栗子
测试代码
allure 报告
description 的栗子
测试代码
test_1(): """ 动态设置描述 """ ) allure.dynamic.description(动态描述")
allure 报告
可以看到动态描述会覆盖动态设置描述
结合 parametrize
测试代码
data = [ (name1",123456name1 登录成功),(name2name2 登录失败name3name3 登录成功) ] @pytest.mark.parametrize('username,pwd,title',data) test_2(username,title): 登录测试用例1 print(username,pwd) allure.dynamic.title(title)
allure 报告
其他属性的栗子
测试代码
test_2(): allure.dynamic.feature(动态feature) allure.dynamic.story(动态story) allure.dynamic.link(https://www.cnblogs.com/poloyy/p/1.html动态Link) allure.dynamic.issue(https://www.cnblogs.com/poloyy/p/2.html动态Issue) allure.dynamic.testcase(https://www.cnblogs.com/poloyy/p/3.html动态testcase')
allure 报告
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。