pytest+allure生成测试报告

若如初见. 提交于 2020-04-25 02:24:24

一 环境搭建与使用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:\Users\acer>powershell     # 进入到powershell
PS C:\Users\acer> 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 ~\scoop\apps\allure\current => ~\scoop\apps\allure\2.13.0
  Creating shim for 'allure'.
  'allure' (2.13.0) was installed successfully! 

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

C:\Users\acer>allure --version
2.13.0

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

C:\Users\acer>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:\myproj\pytest_demo\testcases>pytest --alluredir=report test_fix.py
#生成报告并打开报告,方法一(需要执行两个命令): E:\myproj\pytest_demo\testcases
>allure generate report # 将report 文件夹下的json文件渲染成网页结果,此命令生成的报告默认在allure-report目录,可以通过
allure generate <directory-with-results> -o
<directory-with-report> 修改默认报告的默认目录为<directory-with-report>
E:\myproj\pytest_demo\testcases>allure open allure-report # 本地默认浏览器打开测试报告

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

 

二 allure自定义设置

1.环境变量的设置

效果图:

 

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

Browser=Chrome
Browser.Version=63.0
Stand=Production
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!