以下内容基于pytest的框架进行展示:

什么是Allure

Allure是一个独立的报告插件,生成美观易读的报告,目前支持语言:Java, PHP, Ruby, Python, Scala, C#。

怎么用

Allure安装

安装pytest的插件包pytest-allure-adaptor: pip3 install pytest-allure-adaptor

Allure帮助文档

https://docs.qameta.io/allure/#_about

生成Allure报告

命令行参数:pytest --alluredir report  # 在执行命令目录生成report文件夹,文件夹下包含xml文件

示例:

pytest.ini

[pytest]
;--html=./report.html
#删除原生html,增加Allure
addopts = -s --alluredir report
# 测试路径
testpaths = ./Test
# 测试文件名
python_files = test_*.py
# 测试类名
python_classes = Test_*
# 测试的方法名
python_functions = test_*

注意:ini不支持注释,请去除文本中注释部分

test_all.py

class Test_allure:
def setup(self):
pass
def teardown(self):
pass
def test_al(self):
assert 0

操作步骤:
1.命令行进入pytest.ini所在目录
2.输入命令:pytest
执行结果:
1.pytest.ini所在目录生成report文件夹,文件夹下生成一个xml文件

xml转html工具安装

mac版本

1.:brew install allure
2.进入report上级目录执行命令:allure generate report/ -o report/html
3.report目录下会生成index.html文件,即为可视化报告

windows版本

1.下载压缩包allure-2.6.0.zip
地址:https://bintray.com/qameta/generic/allure2
2.解压
3.将压缩包内的bin目录配置到path系统环境变量
4.进入report上级目录执行命令:allure generate report/ -o report/html --clean
5.report目录下会生成index.html文件,即为可视化报告

Allure之Pytest

添加测试步骤

方法:@allure.step(title="测试步骤001")

示例:
test_all.py

import allure, pytest
class Test_allure:
def setup(self):
pass
def teardown(self):
pass
@allure.step('我是测试步骤001')
def test_al(self, a):
assert a != 2

添加测试描述

方法:allure.attach('描述', '我是测试步骤001的描述~~~')

示例:

test_all.py

import allure, pytest
class Test_allure:
  def setup(self):
    pass
  def teardown(self):
    pass
  @allure.step('我是测试步骤001')
  def test_al(self, a):
    allure.attach('描述', '我是测试步骤001的描述~~~')
    assert a != 2

添加严重级别

测试用例设置不同的严重级别,可以帮助测试和开发人员更直观的关注重要Case.

方法:@pytest.allure.severity(Severity)
参数:
Severity:严重级别(BLOCKER,CRITICAL,NORMAL,MINOR,TRIVIAL)
使用方式:
@pytest.allure.severity(pytest.allure.severity_level.CRITICAL)

示例:

test_all.py

import allure, pytest
class Test_allure:
def setup(self):
pass
def teardown(self):
pass @pytest.allure.severity(pytest.allure.severity_level.CRITICAL)
@allure.step('我是测试步骤001')
def test_al(self, a):
allure.attach('描述', '我是测试步骤001的描述~~~')
assert a != 2

最新文章

  1. MVC5 网站开发实践 概述
  2. spa 单页面解决浏览器back front 问题
  3. runtime学习笔记
  4. html随笔
  5. 使用FFmpeg解码H264-2016.01.14
  6. JS可改变列宽table
  7. php克隆 自动加载
  8. HttpResponse类
  9. SAP ABAP MARD和MARDH计算逻辑
  10. jdbc mysql - Column count doesn't match value count at row 1.
  11. OCP读书笔记(25) - 题库(ExamE)
  12. Java基础知识二次学习-- 第一章 java基础
  13. 【Centos7】安装memcached
  14. SSH框架搭建最终版【测试、log4j、baseDao】
  15. C语言程序设计第三次作业——选择结构(1)
  16. 正则表达式,提取html标签的属性值
  17. Cordova/Ionic Android 开发环境搭建 - Windows系统
  18. 多线程开发之三 GCD
  19. VM虚拟机的配置文件(.vmx)损坏
  20. 安装VS2013

热门文章

  1. 实现Action
  2. sqlserver修改某列为自增
  3. Linux(CENTOS7) Mysql不能远程连接解决办法
  4. Python 学习笔记:Python 中单引号(')、双引号(")、三引号(''',""")的使用以及不转义字符串
  5. 7.docker file 语法
  6. 给Office文档添加水印效果【测试有效】
  7. 吴裕雄--天生自然python Google深度学习框架:图像识别与卷积神经网络
  8. AI大火之下智能手机行业能适应这一风口吗?
  9. 洛谷-P3796-【模板】AC自动机(加强版)
  10. $identify 的 “identify” 表示一个Perl标识符,即 identifier