zoukankan      html  css  js  c++  java
  • pytest--allure

    Allure 是一款轻量级的开源自动化测试报告生成框架。它支持绝大部分测试框架,比如 TestNG、Junit 、pytest、unittest 等。
     
    1.Allure 下载安装
    下载完成之后,解压到 pytest 目录中。然后设置环境变量,简单一点就是进入 allure-2.13.0in 目录执行 allure.bat 。
    cmd 输入 allure 查看环境变量是否设置成功。
     
    2. allure-pytest
    下载 allure-pytest 插件,用来生成 Allure 测试报告所需要的数据。
    pip3 install allure-pytest
     
    案例分析:
    1.编写一段使用 pytest 框架的测试代码:
    #!/usr/bin/env python
    # coding=utf-8
    import pytest
    import allure
    import os
    
    @pytest.fixture(scope='function')
    def login():
        print("登录")
        yield
        print("登录完成")
    
    @allure.feature('加入购物车')
    def test_1(login):
        '''将苹果加入购物车'''
        print("测试用例1")
    
    @allure.feature('加入购物车')
    def test_2():
        '''将橘子加入购物车'''
        print("测试用例2")
    
    if __name__ =="__main__":
        # 执行pytest单元测试,生成 Allure 报告需要的数据存在 /temp 目录
        pytest.main(['--alluredir', './temp'])
        # 执行命令 allure generate ./temp -o ./report --clean ,生成测试报告
        os.system('allure generate ./temp -o ./report --clean') 
     
    @allure 装饰器中的一些功能点:
    @allure.feature :用于定义被测试的功能,被测产品的需求点
    @allure.story : 用于定义被测功能的用户场景,即子功能点
    @allure.step :用于将一个测试用例,分成几个步骤在报告中输出
    @allure.attach : 用于向测试报告中输入一些附加的信息,通常是一些测试数据信息
     
    2.执行后生成 Allure 报告:
     
    打开 index.html ,测试报告如下: chrome打开后报404,尝试用火狐,edge试试~
     
     

  • 相关阅读:
    校验身份证有效性
    JAVA实现redis超时失效key 的监听触发
    Java8中时间日期库的20个常用使用示例
    ppt制作元素采集
    查找数据的网站
    在centos7中python3的安装注意
    使用yum安装不知道到底安装在什么文件夹
    linux为什么不可以添加硬链接
    五一之起一台服务器玩玩-花生壳配置
    centos6.5-vsftp搭建
  • 原文地址:https://www.cnblogs.com/absoluteli/p/13984894.html
Copyright © 2011-2022 走看看