zoukankan      html  css  js  c++  java
  • pytest扫盲24--使用alure标记打造更清晰的报告

    • 背景
    1. 上篇博客介绍了allure集成在Jenkins,以及Jenkins构建本地job的方式.
    2. allure报告不会显示 @pytest.mark 标记的标记名称,这样不太方便阅读.
    3. 本篇博客介绍 allure 自带标记的方式,并可以将标记名称显示在报告中.
    • allure标记的装饰器
    1. BDD标记 @allure.feature/@allure.story
    2. 优先级标记 @allure.severity(@allure.severity_level.[Severity])
    3. 自定义标记
    • BDD标记
      @allure.feature
      @allure.story
    @allure.feature('feature_1')
    @allure.story('story_1')
    def test_1(login):
        print('*' * 5 + 'test_1' + '*' * 5)
        a = 'hello world!'
        assert 'hello' in a
    
    @allure.story('story_2')
    def test_2():
        print('*' * 5 + 'test_2' + '*' * 5)
        x = 'hello world!'
        assert hasattr(x, 'helloWorld')
    
    @allure.story('story_3')
    def test_3():
        print('*' * 5 + 'test_3' + '*' * 5)
        b = 3
        assert b == 4
    
    • 执行结果
    1. 报告中 feature by storys 栏目显示了 allure 标记
    2. show all 查看详情

    • 结论
    1. story 是 feature 的子集
    2. 测试用例会按照 allure 标记分类显示,报告层次更鲜明
    3. 是否可以用 allure 标记替代 @pytest.mark?
      答案是肯定的,@pytest.mark可以指定运行的用例,allure标记同样也可以
    • 指定命令运行allure标记

    --allure-features
    --allure-stories
    指定命令运行:
    pytest test_demo_2.py --allure-features feature_1

    也可以这样:pytest test_demo_2.py --allure-features feature_1 --allure-stories story_1

    • 优先级标记
      @allure.severity(@allure.severity_level.[Severity])
    • [Severity]类型:
    class Severity(str, Enum):
        BLOCKER = 'blocker'
        CRITICAL = 'critical'
        NORMAL = 'normal'
        MINOR = 'minor'
        TRIVIAL = 'trivial'
    
    • 使用@allure.severity
    @allure.severity(allure.severity_level.NORMAL)
    def test_2():
        print('*' * 5 + 'test_2' + '*' * 5)
        x = 'hello world!'
        assert hasattr(x, 'helloWorld')
    
    @allure.severity(allure.severity_level.CRITICAL)
    def test_3():
        print('*' * 5 + 'test_3' + '*' * 5)
        pass
    
    • 执行代码
      pytest -s . est_demo_2.py --allure-severities normal,critical --alluredir report
  • 相关阅读:
    Jzoj5542 董先生的钦点
    Jzoj5542 董先生的钦点
    (各种)FFT模板
    (各种)FFT模板
    Jzoj3528 图书馆
    Jzoj3528 图书馆
    Jzoj5317 Func
    Jzoj5317 Func
    Jzoj3591 数据
    【UVa11021】Tribles
  • 原文地址:https://www.cnblogs.com/xiaohuboke/p/13597213.html
Copyright © 2011-2022 走看看