zoukankan      html  css  js  c++  java
  • pytest +allure 报告生成

    第一步:pip install pytest-allure-adaptor

    第二步:编写用例

    import allure
    import pytest
    """
    Feature: 标注主要功能模块
    Story: 标注Features功能模块下的分支功能
    Severity: 标注测试用例的重要级别
    Step: 标注测试用例的重要步骤
    Issue和TestCase: 标注Issue、Case,可加入URL
    attach: 标注增加附件
    Environment: 标注环境Environment字段
    
    """
    # 环境
    allure.MASTER_HELPER.environment(域名="127.0.0.1")
    
    
    @allure.MASTER_HELPER.feature("测试")
    class TestClassOne:
        @allure.MASTER_HELPER.story("test_one_1")
        @allure.MASTER_HELPER.severity("normal")
        # 运行步骤
        @allure.MASTER_HELPER.step("单元相当")
        def test_one_1(self):
            with allure.MASTER_HELPER.step("获取变量a"):
                a = 3
            with allure.MASTER_HELPER.step("获取变量b"):
                b = 2
            allure.MASTER_HELPER.attach("预期结果", "{0}".format("1"))
            allure.MASTER_HELPER.attach("实际结果", "{0}".format("2"))
            x = "this"
            assert 't' in x
    
        @allure.MASTER_HELPER.story("test_two_2")
        @allure.MASTER_HELPER.severity("normal")
        def test_two_2(self):
            """用例描述拉"""
            x = "hello"
            assert hasattr(x, 'check')
    
        @allure.MASTER_HELPER.story("test_one_1")
        @allure.MASTER_HELPER.severity("normal")
        def test_one_3(self):
            x = "this"
            assert 't' in x
    
        @allure.MASTER_HELPER.story("test_two_2")
        @allure.MASTER_HELPER.severity("normal")
        def test_two_4(self):
            x = "hello"
            assert hasattr(x, 'check')
    
        @allure.MASTER_HELPER.story("test_one_1")
        @allure.MASTER_HELPER.severity("normal")
        def test_one_5(self):
            x = "this"
            assert 't' in x
    
        @allure.MASTER_HELPER.story("test_two_2")
        @allure.MASTER_HELPER.severity("normal")
        def test_two_6(self):
            x = "hello"
            assert hasattr(x, 'check')
    
        @allure.MASTER_HELPER.story("test_one_1")
        @allure.MASTER_HELPER.severity("trivial")
        def test_one_7(self):
            x = "this"
            assert 't' in x
    
        @allure.MASTER_HELPER.story("test_two_2")
        @allure.MASTER_HELPER.severity("normal")
        def test_two_8(self):
            x = "hello"
            assert hasattr(x, 'check')
    
    
    import os
    
    if __name__ == '__main__':
        """
        --reruns 重试
        -s 显示print内容
        
        """
        pytest.main(['-s', '--reruns', '10', '-q', 'test_pytestdemo.py', '--alluredir', './report/xml'])
        os.system("allure generate report/xml -o report/html")
    

      #执行后自动打开报告 allure serve allure 

      执行一下命令

    生成xml数据

    pytest -s -q --alluredir=report
    生成报告
    allure generate report/ -o report/html

  • 相关阅读:
    追踪神秘的成都Uber:月入2万元是现实还是传说
    打造自己博客(wordpress)的wap手机版本
    今天刚申请成为Uber司机 已经接了5单了....大家有什么想问的吗?
    UBER司机奖励政策
    原生应用native、Web应用、混合应用hybrid:3者的优缺点解析
    “基数排序”之数组中缺失的数字
    html5 新增语义标签
    如何判断Javascript对象是否存在
    HTML 5 <details> 标签
    html5 notifications通知
  • 原文地址:https://www.cnblogs.com/mahaining/p/11534041.html
Copyright © 2011-2022 走看看