Python + allure 报告

安装

Windows安装allure需要先安装scoop,确保安装了PowerShell 5(或更高版本,包括PowerShell Core)和. net Framework 4.5(或更高版本)。然后打开PowerShell运行: iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
在这里插入图片描述
安装allure:scoop install allure
在这里插入图片描述
貌似国内没有梯子的后来这种安装方式不行了,一直安装scoop失败,特意加了手动安装的方法

手动安装
  • Maven Central 下载最新的版本的压缩包
  • 解压缩,定位到bin目录下
  • 将该路径添加到环境变量PATH
安装pytest-allure插件,运行:pip install allure-pytest
使用

运行测试用例:pytest --alluredir=/tmp/my_allure_results
直接打开测试报告:allure serve /tmp/my_allure_results 将会在默认浏览器中打开测试报告:在这里插入图片描述

或者生成测试报告:allure generate /tmp/my_allure_results -o /tmp/report --clean
打开测试报告:allure open -h 127.0.0.1 -p 8083 /tmp/report
目前allure2暂不支持allure.environment(platform_name=‘Android’)这种方法设置环境注解,不过在生成报告之前,可以通过把environment.properties (or environment.xml) 文件放到生成的allure-results文件夹下来添加(参考:Environment)。
environment.properties

Browser=Chrome
Browser.Version=63.0
Stand=Production

environment.xml

<environment>
    <parameter>
        <key>Browser</key>
        <value>Chrome</value>
    </parameter>
    <parameter>
        <key>Browser.Version</key>
        <value>63.0</value>
    </parameter>
    <parameter>
        <key>Stand</key>
        <value>Production</value>
    </parameter>
</environment>
集成jenkins
  1. 安装 Allure Plugin插件,jenkins的Manage Jenkins->Manage Plugins->查找Allure Jenkins Plugin并安装

  2. 配置command,Manage Jenkins->Global Tool Configuration找到Allure Commandline,点击Allure Commandline installations…,点击保存即可。在这里插入图片描述

  3. 创建一个pipline的项目,输入以下脚本:

    pipeline {
        agent any
        stages {
            stage('Example') {
                steps {
                    echo "hello World!"
                    bat 'cd C:\\your-path && pytest --alluredir=result -s -v login_scenario.py'
                }
            }
        }
        post("Report"){
            always{
                script{
                    allure includeProperties: false, jdk: '', report: 'report', results: [[path: 'result']]            }
            }
        }
    }
    
参考:
  1. https://docs.qameta.io/allure/#_python
  2. https://testerhome.com/topics/15649
  3. https://github.com/allure-framework/allure-python/tree/master/allure-pytest
  • 4
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值