• python-pytest-Allure2测试报告生成


    Allure:

    Allure框架是一种灵活的轻量级多语言测试报告工具,它以简洁的web报告形式显示已测试的内容。

    安装环境(win10):

    1. 安装JDK1.8+环境:
      Allure需要java8+,JDK 1.8+ 环境,所以要提前配置好java环境。
      官方下载地址:https://www.oracle.com/java/technologies/javase-jdk8-downloads.html,1.8后的jdk会自动添加环境变量
    2. 安装Allure:
      https://github.com/allure-framework/allure2/releases  进行下载,下载Links中Download的压缩包之后,解压到本地
    3. 安装allure命令:
      pip install allure-pytest
      安装完成会提示:Installing collected packages: allure-python-commons, allure-pytest
      Successfully installed allure-pytest-2.8.13 allure-python-commons-2.8.13

    allure用例描述:

    1. allure.epic("xxx") ----------------> 参数:敏捷测试中的概念 史诗,可以理解为项目级别的描述
    2. allure.feature("xxx") ------------>  参数:模块描述,功能点描述
    3. allure.stroy("xxx") --------------->  参数:用例描述,用例故事
    4. allure.title("xxx") -----------------> 参数:用例重命名的标题,显示报告中,不重命名则显示函数/方法名
    5. allure.step("xxx") ----------------> 参数:测试步骤的描述
    6. allure.description("xxx") -------> 参数:测试用例描述
    7. allure.severity("xxx") -----------> 参数:用例等级(blocker、critical、normal、minor、trivial)
    8. allure.attachment("xxx") ------> 参数:报告中添加的附件
    9. allure.testcase("xxx") ----------> 参数:功能测试用例链接地址
    10. allure.issue("xxx") --------------> 参数:缺陷链接地址
    11. allure.link("xxx") -----------------> 参数:定义一个链接,显示在报告中

    添加environment:

    通过创建environment.properties或者environment.xml文件,并把文件存放到报告依赖文件的同级目录下,就是--alluredir 后面跟的目录

    # environment.xml文件如下:
    <environment>
        <parameter>
            <key>Browser</key>
            <value>Chrome</value>
        </parameter>
    </environment>
    # environment.properties文件内容
    Browser = Chrome
    python.Version = 3.7.2

    添加categories:

    分类:测试结果的分类,默认两类缺陷

    1. Product defects 产品缺陷 (测试结果failed)

    2. Test defects 测试缺陷 (测试结果:error/broken)

    我们可以自定义缺陷,将categories.json 文件添加到 报告文件存放的目录

    # 官方例子 categories.json
    [
        {
            "name": "Ignored tests",
            "matchedStatuses": ["skipped"]
        },
        {
            "name": "Infrastructure problems",
            "matchedStatuses": ["broken", "failed"],
            "messageRegex": ".*bye-bye.*"
        },
        {
            "name": "Outdated tests",
            "matchedStatuses": ["broken"],
            "traceRegex": ".*FileNotFoundException.*"
        },
        {
            "name": "Product defects",
            "matchedStatuses": ["failed"]
        },
        {
            "name": "Test defects",
            "matchedStatuses": ["broken"]
        }
    ]

    官方字段解释:

    name: (mandatory) category name
    matchedStatuses:(optional) list of suitable test statuses. Default ["failed", "broken", "passed", "skipped", "unknown"]
    messageRegex: (optional) regex pattern to check test error message. Default ".*"
    traceRegex: (optional) regex pattern to check stack trace. Default ".*"

    pytest 执行并生成报告的过程:

    pytest --alluredir ./report/allure_raw

    执行完成后,在当前目录下,report目录会生成一个allure_raw的原始文件,这个只是测试报告的原始文件,不能打开成html的报告。

    allure serve report/allure_raw

    启动服务,它会自动给个端口,直接用默认浏览器打开了,也可以手动复制地址在其他浏览器中打开。

    指定执行用例:

    pytest --alluredir ./report/allure --allure-epics="epic的描述信息"
    pytest --alluredir ./report/allure --allure-features="feature描述"
    pytest --alluredir ./report/allure --allure-stories="story描述"
  • 相关阅读:
    计算机操作系统 存储器管理
    数据结构 平衡二叉树avl c++
    数据结构 线索二叉树 c++
    数据结构 赫夫曼树及其应用 c++
    c++ cstring 常用函数
    数据结构 哈希表 c++
    数据结构 静态链表
    ajax返回填充的数据不显示
    使用JSON.parse()转化成json对象需要注意的地方
    参数错误导致bug
  • 原文地址:https://www.cnblogs.com/belle-ls/p/12755403.html
Copyright © 2020-2023  润新知