如果你还想从头学起Pytest,可以看看这个系列的文章哦!
https://www.cnblogs.com/poloyy/category/1690628.html
前言
- 平时写测试用例也会划分优先级
- 同样,allure 也提供用例级别,在 allure 报告可以清晰看到不同级别用例的缺陷数量
用例等级介绍
allure 提供的枚举类
等级介绍
- blocker:阻塞缺陷(功能未实现,无法下一步)
- critical:严重缺陷(功能点缺失)
- normal: 一般缺陷(边界情况,格式错误)
- minor:次要缺陷(界面错误与ui需求不符)
- trivial: 轻微缺陷(必须项无提示,或者提示不规范)
实际栗子
测试代码
#!/usr/bin/env python # -*- coding: utf-8 -*- """ __title__ = __Time__ = 2020-04-19 14:50 __Author__ = 小菠萝测试笔记 __Blog__ = https://www.cnblogs.com/poloyy/ """ import allure def test_with_no_severity_label(): pass @allure.severity(allure.severity_level.TRIVIAL) test_with_trivial_severity(): @allure.severity(allure.severity_level.norMAL) test_with_normal_severity(): class TestClassWithnormalSeverity(object): test_inside_the_normal_severity_test_class(self): 测试类优先级 normal;看看测试用例是否会自动继承优先级 """ print() @allure.severity(allure.severity_level.CRITICAL) test_inside_the_normal_severity_test_class_with_overriding_critical_severity(self): 测试类优先级 normal 测试用例优先级 critical @allure.severity("normal") test_case_1(): normal 级别测试用例 """ print(test case 11111111) @allure.severity(critical test_case_2(): critical 级别测试用例 test case 222222222blocker test_case_3(): blocker 级别测试用例 test case 4444444minor test_case_4(): minor 级别测试用例 ) test_case_5(): 没标记 severity 的用例默认为 normaltest case 5555555555")
allure 报告
测试用例详情
多了个 severity 字段
统计图表
可以看到不同 severity 测试用例运行的统计数据
必然测试失败的测试代码
将上面代码的三个测试用例故意让它测试失败
@allure.severity(assert (1 == 2assert (1 == 2)
再来看看 allure 报告的统计图表
- 这里用的是中文报告,其实可以看到 severity 官方是翻译为优先级,但是如果自己去翻译软件翻译的话是严重程度,我个人更偏向于理解为优先级
- 会同时显示同一个优先级的失败、通过用例数,以及哪条用例是失败、通过的
命令行参数 allure-severities
当然,也可以根据优先级选择需要运行的测试用例
具体栗子
仍然是上面的代码,打开 cmd
只运行 severity=blocker、critical 的测试用例 pytest test_severity.py -sq --alluredir=./allure --allure-severities=blocker,critical 写法二 pytest test_severity.py -sq --alluredir=./allure --allure-severities blocker,critical
运行结果
severi=blocker、critical 的测试用例就三条,可以看看上面的代码
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。