安装

Windows安装allure需要先安装​https://scoop.sh/">​scoop​​,确保安装了PowerShell 5(或更高版本,包括PowerShell Core)和. net Framework 4.5(或更高版本)。然后打开PowerShell运行: ​​iex (new-object net.webclient).downloadstring('https://get.scoop.sh')​

Python + allure 报告_测试报告

安装allure:​​scoop install allure​

Python + allure 报告_Python_02

貌似国内没有梯子的后来这种安装方式不行了,一直安装​​scoop​​失败,特意加了手动安装的方法

手动安装


  • 从 ​​Maven Central​​ 下载最新的版本的压缩包
  • 解压缩,定位到​​bin​​目录下
  • 将该路径添加到环境变量​​PATH​​中

安装pytest-allure插件,运行:​​pip install allure-pytest​

使用

运行测试用例:​​pytest --alluredir=/tmp/my_allure_results​

直接打开测试报告:​​allure serve /tmp/my_allure_results​​ 将会在默认浏览器中打开测试报告:Python + allure 报告_报告_03

或者生成测试报告:​​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…,点击保存即可。Python + allure 报告_测试报告_04
  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​