使用Allure生成漂亮的测试报告(下)

发表于:2021-1-08 10:13

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:secoder    来源:博客园

  allure标记
  作用:
  有时候我们写pytest的时候,会用到 @pytest.mark 但并不会显示在allure报告上。
  allure也提供了三种类型的标记装饰器,它们是可以显示在allure报告上的。
  allure标记装饰器分类
  ·BDD样式的标记装饰器
  ·优先级(严重程度)标记装饰器
  ·自定义标记装饰器
  ·BDD标记装饰器
  提供了两个装饰器
  @allure.feature
  @allure.story
  知识点:
  story是feature的子集,当测试用例有 @allure.feature、@allure.story 时,在报告上会先显示feature,点开之后再显示story【可以想象成,安徒生童话(feature)有很多个童话故事(story)】。
  如果不加 @allure.feature、@allure.story 时,在Behaviors栏目下,测试用例都不会分类显示,当用例多的时候可能看的花里胡哨。
  总结:
  倘若是用pytest+allure写项目的话,又想用@pytest.mark.xxx 来自定义标记的话可以尝试用 @allure.feature、@allure.story 替换,毕竟可以显示在报告上。
  补充:
  用命令行方式运行时,可以指定运行某个story或者feature:
  pytest tests.py --allure-stories story_1,story_2
  pytest tests.py --allure-features feature2 --allure-stories story2
import allure


def test_without_any_annotations_that_wont_be_executed():
    pass


@allure.story('epic_1')
def test_with_epic_1():
    pass


@allure.story('story_1')
def test_with_story_1():
    pass


@allure.story('story_2')
def test_with_story_2():
    pass


@allure.feature('feature_2')
@allure.story('story_2')
def test_with_story_2_and_feature_2():
    pass
  allure.severity
  作用:按严重性(优先级)来标记测试用例,它使用allure.severity_level枚举值作为参数。
  枚举严重程度常量:严重程度最高blocker,最低trivial。
class Severity(str, Enum):
    BLOCKER = 'blocker'
    CRITICAL = 'critical'
    NORMAL = 'normal'
    MINOR = 'minor'
    TRIVIAL = 'trivial'
  命令行方式:也可以通过命令行参数运行指定severity的测试用例。
  pytest tests.py --allure-severities normal,critical
import allure


def test_with_no_severity_label():
    pass


@allure.severity(allure.severity_level.TRIVIAL)
def test_with_trivial_severity():
    pass


@allure.severity(allure.severity_level.NORMAL)
def test_with_normal_severity():
    pass


@allure.severity(allure.severity_level.NORMAL)
class TestClassWithNormalSeverity(object):

    def test_inside_the_normal_severity_test_class(self):
        pass

    @allure.severity(allure.severity_level.CRITICAL)
    def test_inside_the_normal_severity_test_class_with_overriding_critical_severity(self):
        pass
print("test")
test

  本文内容不用于商业目的,如涉及知识产权问题,请权利人联系51Testing小编(021-64471599-8017),我们将立即处理
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号