• pytest+allure生成测试报告


    一 环境搭建与使用demo

    二 allure自定义设置

    jenkins+python+allure持续集成

    一 环境搭建与使用demo

    环境信息:python3.6.5 pytest5.1.2 allure2.13.0  allure-pytest2.8.5

    allure的官方教程https://docs.qameta.io/allure/

    windows10下教程

    1.安装pytest与allure-pytest

    cmd下执行:

    pip install pytest             # python的第三方单元测试框架
    pip install allure-pytest      # 用于连接pytest和allure,这一步会安装allure-pytest和allure-python-commons包

    2.安装allure(官方安装说明https://docs.qameta.io/allure/#_installing_a_commandline

    首先安装windows下安装scoop

    然后在cmd下执行如下红色命令:

    C:Usersacer>powershell     # 进入到powershell
    PS C:Usersacer> scoop install allure   # 安装allure

      Installing 'allure' (2.13.0) [64bit]
      allure-commandline-2.13.0.zip (16.3 MB) [===========================================================================================================================================] 100%
      Checking hash of allure-commandline-2.13.0.zip ... ok.
      Extracting allure-commandline-2.13.0.zip ... done.
      Linking ~scoopappsallurecurrent => ~scoopappsallure2.13.0
      Creating shim for 'allure'.
      'allure' (2.13.0) was installed successfully! 

    检查allure版本:cmd下执行 allure --version

    C:Usersacer>allure --version
    2.13.0

    查看allure用法:cmd下执行allure help(以下只是部分示例)

    C:Usersacer>allure --help
    Usage: allure [options] [command] [command options]
      Options:
        --help
          Print commandline help.
        -q, --quiet
          Switch on the quiet mode.
          Default: false
        -v, --verbose
          Switch on the verbose mode.
          Default: false
        --version
          Print commandline version.
          Default: false
      Commands:
        generate      Generate the report
          Usage: generate [options] The directories with allure results
            Options:
              -c, --clean
                Clean Allure report directory before generating a new one.
                Default: false
              --config
                Allure commandline config path. If specified overrides values from
                --profile and --configDirectory.
              --configDirectory
                Allure commandline configurations directory. By default uses
                ALLURE_HOME directory.
              --profile
                Allure commandline configuration profile.
              -o, --report-dir, --output
                The directory to generate Allure report into.
                Default: allure-report
    
        serve      Serve the report
          Usage: serve [options] The directories with allure results
            Options:
              --config
                Allure commandline config path. If specified overrides values from
                --profile and --configDirectory.
              --configDirectory
                Allure commandline configurations directory. By default uses
                ALLURE_HOME directory.
              -h, --host
                This host will be used to start web server for the report.
              -p, --port
                This port will be used to start web server for the report.
                Default: 0
              --profile
                Allure commandline configuration profile.
    
        open      Open generated report
          Usage: open [options] The report directory
            Options:
              -h, --host
                This host will be used to start web server for the report.
              -p, --port
                This port will be used to start web server for the report.
                Default: 0
    
        plugin      Generate the report
          Usage: plugin [options]
            Options:
              --config
                Allure commandline config path. If specified overrides values from
                --profile and --configDirectory.
              --configDirectory
                Allure commandline configurations directory. By default uses
                ALLURE_HOME directory.
              --profile
                Allure commandline configuration profile.
    View Code

    3简单使用demo

     进入测试用例目录在Terminal下执行如下命令:

    E:myprojpytest_demo	estcases>pytest --alluredir=report test_fix.py
    #生成报告并打开报告,方法一(需要执行两个命令): E:myprojpytest_demo estcases
    >allure generate report # 将report 文件夹下的json文件渲染成网页结果,此命令生成的报告默认在allure-report目录,可以通过
    allure generate <directory-with-results> -o
    <directory-with-report> 修改默认报告的默认目录为<directory-with-report>
    E:myprojpytest_demo	estcases>allure open allure-report # 本地默认浏览器打开测试报告。也可以直接进入到allure-report,使用浏览器查看index.html


    #生成报告并打开报告,方法二(只需要执行一个命令):
    allure serve allure-report

    二 allure自定义设置

    1.环境变量的设置

    效果图:

     实现方式:在 allure-results目录创建文件 environment.properties,并写入如下内容

    Browser=Chrome
    Browser.Version=63.0
    Stand=Production
  • 相关阅读:
    Spring boot返回值封装与业务异常
    Spring boot日志
    Rocket项目启动
    抉择
    C# 字符转ASCII码,ASCII码转字符 [转一下]
    xcode 学习笔记2:动态添加view
    unrecognized selector sent to instance 0x1b97e0' 问题解决记录
    xcode 学习笔记1:Interface Builder的使用
    xcode 学习笔记4:给WindowBase程序添加view
    xcode 学习笔记3:xcode目录结构
  • 原文地址:https://www.cnblogs.com/wang-mengmeng/p/11513026.html
Copyright © 2020-2023  润新知