pytest中allure自动化测试报告的配置与安装

pytest的allure自动化测试报告的配置与安装

allure的下载安装

  • https://github.com/allure-framework/allure2/releases
  • 打开上面的网址下载最新的allure的压缩包
    pytest中allure自动化测试报告的配置与安装_第1张图片
  • 下载好之后解压到英文路径下,我的是
E:\Program Files\allure-2.13.5
  • 之后打开电脑属性的高级系统设置添加环境变量
  • 在系统变量path中添加allure的安装路径并且确定保存,如上文
    pytest中allure自动化测试报告的配置与安装_第2张图片
  • 打开cmd输入allure,若出现下文则是安装成功
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.
  • 之后进入pycharm,安装allure-pytest包就可以运行pytest用例
  • 运行语法如下
方法一,在py文件里面写主函数
if __name__ =="__main__":
    # 执行pytest单元测试,生成 Allure 报告需要的数据存在report 目录
    #若没有report目录会自动创建
    pytest.main(['文件名.py','--alluredir',  '/report'])
    # 执行命令 allure generate ,生成测试报告
    #其中report是之前装allure文件的目录
    #clean是清除原先文件夹里的报告
    os.system('allure generate report --clean')
方法二,在pycharm的Dos界面写命令
>pytest --alluredir report
>allure generate report --clean
#原理和方法一类似
  • 执行完之后会发现allure-report文件夹下会有一个index.html文件
  • 用浏览器打开就能发现报告

你可能感兴趣的:(pytest)