python pytest allure_【转载】Python—Pytest+Allure定制报告

Allure Test Report

一款测试报告框架,不仅报告美观,而且方便CI集成。

一、环境配置

安装Python依赖库:

pip3 install pytest

pip3 install pytest-allure-adaptor

安装 Command Tool:

brew tap qatools/formulas

brew install allure-commandline

二、生成html报告命令

1、pytest命令基础上加–alluredir,生成xml报告。

pytest -s -q –alluredir [xml_report_path]

//[xml_report_path]根据自己需要定义文件夹,作者定义为:/report/xml

用例执行完成之后会在[xml_report_path]目录下生成了一堆xml的report文件,当然这不是我们最终想要的美观报告。

python pytest allure_【转载】Python—Pytest+Allure定制报告

2、需要使用 Command Tool 来生成我们需要的美观报告。

allure generate [xml_report_path] -o [html_report_path] –clean

//[html_report_path]根据自己需要定义文件夹,作者定义为:/report/html

3、通过下面的命令打开测试报告:

allure open -h 127.0.0.1 -p 8083[html_report_path]

打开 index.html,之前写的 case 报告就会呈现在你面前,如下:

python pytest allure_【转载】Python—Pytest+Allure定制报告

注:直接用chrome浏览器打开报告,报告可能会是空白页面。

解决办法:

1、在pycharm中右击index.html选择打开方式Open in Browser就可以了。

2、使用Firefox直接打开index.html。

三、定制报告

Feature: 标注主要功能模块

Story: 标注Features功能模块下的分支功能

Severity: 标注测试用例的重要级别

Step: 标注测试用例的重要步骤

Issue和TestCase: 标注Issue、Case,可加入URL

1、Features定制详解

– coding: utf-8 –

@Time : 2018/8/17 上午10:10

@Author : WangJuan

@File : test_case.py

import allure

import pytest

@allure.feature(‘test_module_01’)

def test_case_01():

“””

用例描述:Test case 01

“””

assert 0

@allure.feature(‘test_module_02’)

def test_case_02():

“””

用例描述:Test case 02

“””

assert 0 == 0

if name == ‘main‘:

pytest.main([‘-s’, ‘-q’, ‘–alluredir’, ‘./report/xml’])

添加feature,Report展示见下图:

python pytest allure_【转载】Python—Pytest+Allure定制报告

2、Story定制详解

– coding: utf-8 –

@Time : 2018/8/17 上午10:10

@Author : WangJuan

@File : test_case.py

import allure

import pytest

@allure.feature(‘test_module_01’)

@allure.story(‘test_story_01’)

def test_case_01():

“””

用例描述:Test case 01

“””

assert 0

@allure.feature(‘test_module_01’)

@allure.story(‘test_story_02’)

def test_case_02():

“””

用例描述:Test case 02

“””

assert 0 == 0

if name == ‘main‘:

pytest.main([‘-s’, ‘-q’, ‘–alluredir’, ‘./report/xml’])

添加story,Report展示见下图:

python pytest allure_【转载】Python—Pytest+Allure定制报告

3、用例标题和用例描述定制详解

– coding: utf-8 –

@Time : 2018/8/17 上午10:10

@Author : WangJuan

@File : test_case.py

import allure

import pytest

@allure.feature(‘test_module_01’)

@allure.story(‘test_story_01’)

test_case_01为用例title

def test_case_01():

“””

用例描述:这是用例描述,Test case 01,描述本人

“””

注释为用例描述

assert 0

if name == ‘main‘:

pytest.main([‘-s’, ‘-q’, ‘–alluredir’, ‘./report/xml’])

添加用例标题和用例描述,Report展示见下图:

python pytest allure_【转载】Python—Pytest+Allure定制报告

4 、Severity定制详解

Allure中对严重级别的定义:

1、 Blocker级别:中断缺陷(客户端程序无响应,无法执行下一步操作)

2、 Critical级别:临界缺陷( 功能点缺失)

3、 Normal级别:普通缺陷(数值计算错误)

4、 Minor级别:次要缺陷(界面错误与UI需求不符)

5、 Trivial级别:轻微缺陷(必输项无提示,或者提示不规范)

– coding: utf-8 –

@Time : 2018/8/17 上午10:10

@Author : WangJuan

@File : test_case.py

import allure

import pytest

@allure.feature(‘test_module_01’)

@allure.story(‘test_story_01’)

@allure.severity(‘blocker’)

def test_case_01():

“””

用例描述:Test case 01

“””

assert 0

@allure.feature(‘test_module_01’)

@allure.story(‘test_story_01’)

@allure.severity(‘critical’)

def test_case_02():

“””

用例描述:Test case 02

“””

assert 0 == 0

@allure.feature(‘test_module_01’)

@allure.story(‘test_story_02’)

@allure.severity(‘normal’)

def test_case_03():

“””

用例描述:Test case 03

“””

assert 0

@allure.feature(‘test_module_01’)

@allure.story(‘test_story_02’)

@allure.severity(‘minor’)

def test_case_04():

“””

用例描述:Test case 04

“””

assert 0 == 0

if name == ‘main‘:

pytest.main([‘-s’, ‘-q’, ‘–alluredir’, ‘./report/xml’])

添加Severity,Report展示见下图:

python pytest allure_【转载】Python—Pytest+Allure定制报告

5、Step定制详解

– coding: utf-8 –

@Time : 2018/8/17 上午10:10

@Author : WangJuan

@File : test_case.py

import allure

import pytest

@allure.step(“字符串相加:{0},{1}”)

测试步骤,可通过format机制自动获取函数参数

def str_add(str1, str2):

if not isinstance(str1, str):

return “%s is not a string” % str1

if not isinstance(str2, str):

return “%s is not a string” % str2

return str1 + str2

@allure.feature(‘test_module_01’)

@allure.story(‘test_story_01’)

@allure.severity(‘blocker’)

def test_case():

str1 = ‘hello’

str2 = ‘world’

assert str_add(str1, str2) == ‘helloworld’

if name == ‘main‘:

pytest.main([‘-s’, ‘-q’, ‘–alluredir’, ‘./report/xml’])

添加Step,Report展示见下图:

python pytest allure_【转载】Python—Pytest+Allure定制报告

6、Issue和TestCase定制详解

– coding: utf-8 –

@Time : 2018/8/17 上午10:10

@Author : WangJuan

@File : test_case.py

import allure

import pytest

@allure.step(“字符串相加:{0},{1}”) # 测试步骤,可通过format机制自动获取函数参数

def str_add(str1, str2):

print(‘hello’)

if not isinstance(str1, str):

return “%s is not a string” % str1

if not isinstance(str2, str):

return “%s is not a string” % str2

return str1 + str2

@allure.feature(‘test_module_01’)

@allure.story(‘test_story_01’)

@allure.severity(‘blocker’)

@allure.issue(“http://www.baidu.com”)

@allure.testcase(“http://www.testlink.com”)

def test_case():

str1 = ‘hello’

str2 = ‘world’

assert str_add(str1, str2) == ‘helloworld’

if name == ‘main‘:

pytest.main([‘-s’, ‘-q’, ‘–alluredir’, ‘./report/xml’])

添加Issue和TestCase,Report展示见下图:

python pytest allure_【转载】Python—Pytest+Allure定制报告

8、attach定制详解

file = open(‘../test.png’, ‘rb’).read()

allure.attach(‘test_img’, file, allure.attach_type.PNG)

在报告中增加附件:allure.attach(‘arg1′,’arg2′,’arg3’):

arg1:是在报告中显示的附件名称

arg2:表示添加附件的内容

arg3:表示添加的类型(支持:HTML,JPG,PNG,JSON,OTHER,TEXTXML)

添加attach参数,Report展示见下图:

python pytest allure_【转载】Python—Pytest+Allure定制报告

Original: https://blog.csdn.net/weixin_36035466/article/details/113493386
Author: 英论阁Enago科研作者服务
Title: python pytest allure_【转载】Python—Pytest+Allure定制报告

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/776758/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • numpy中的滑动窗口函数

    lib.stride_tricks.sliding_window_view(x, window_shape, axis=None, *, subok=False, writeabl…

    Python 2023年8月28日
    0152
  • 30个在线Python自学网站,再也不用到处找资料了

    本文就是给大家推荐一些 既能在线自学(视频),又可以在线编程的Python学习网站。 老规矩,简单介绍一下Python,与 Java、Perl、PHP 和 Ruby 等其他语言相比…

    Python 2023年8月2日
    071
  • Anaconda和Conda的使用

    直接去anaconda官网下载安装文件即可,具体网站自行搜索。官网提供linux版本,windows版本,mac版本。同时提供Anaconda完整版和miniconda最小版(无软…

    Python 2023年9月9日
    054
  • pytorch:深入理解 reshape(), view(), transpose(), permute() 函数

    文章目录 * – 前言 – 1. reshape() – 2. view() – + ① 1 阶变高阶 + * 1 阶变 2 阶 *…

    Python 2023年10月11日
    072
  • HDFS 高可用分布式环境搭建

    原文地址: 然后在 node01 上执行 stop-dfs.sh 重新规划每个节点的职责 host NN JNN DN ZKFC ZK node01 √ √ √ node02 √ …

    Python 2023年10月22日
    044
  • 【自考】数据结构第五章图,期末不挂科指南,第9篇

    图的基本概念 首先,你要明确图是什么样子的,就是下面这个样子的 图的定义与术语 有向图和无向图 直接对比图就可以看出来,有向图和无向图的区别了,这个没有什么难的。 有向图和无向图的…

    Python 2023年6月3日
    0190
  • Pandas数据清洗总结

    # 导入 import numpy as np import pandas as pd # 查看版本 pd.version 文本文件的读取: 对于csv或txt后缀的文本文件,用r…

    Python 2023年8月19日
    046
  • KMP&Z函数详解

    KMP 一些简单的定义: 真前缀:不是整个字符串的前缀 真后缀:不是整个字符串的后缀 当然不可能这么简单的,来个重要的定义 前缀函数: 给定一个长度为(n)的字符串(s),其(前缀…

    Python 2023年10月21日
    071
  • Anaconda命令行总结

    总结conda或者pip常见命令 2022年03月11日19:38:01 个人建议学习python最好使用anaconda+pycharm,自己从2020大四初学python以来,…

    Python 2023年9月8日
    052
  • [Python图像处理] 使用OpenCV检测对象颜色

    使用OpenCV检测对象颜色 * – 前言 – 使用 OpenCV 检测对象颜色 – 相关链接 前言 检测图像中对象颜色的一种简单方法是首先将图…

    Python 2023年9月29日
    048
  • MAE详解

    目录 一、介绍 二、网络结构 1. encoder 2. decoder 3. LOSS 三、实验 全文参考:论文阅读笔记:Masked Autoencoders Are Scal…

    Python 2023年9月28日
    055
  • pytest-fixture

    pytest-fixture 一、适用范围 1.替代setup和teardown2.参数化如何使用:1.给要使用的方法传入fixture的函数名2.使用装饰器@pytest.mar…

    Python 2023年9月14日
    048
  • webpack打包优化的几种手段

    作用主要是过滤不需要解析的文件,比如打包的时候依赖了三方库(jquyer、lodash)等,而这些三方库里面没有其他依赖,可以通过配置noParse不去解析文件,提高打包效率。是m…

    Python 2023年10月22日
    042
  • pandas 高级

    目录 前言 1.数据集成 * 1.1 concat数据串联 1.2 插入 1.3 Join SQL风格合并 2.数据清洗 * 2.1 重复数据过滤 2.2 空数据过滤 2.3 指定…

    Python 2023年8月28日
    049
  • centos安装python3/pip3项目所需的第三方模块(在线安装&&离线安装)

    文章目录 前言 * 安装python3和pip3 安装项目所需的模块 – 在线安装所需模块 离线安装/下载所需模块和离线包 + ①、单个模块下载&&指定…

    Python 2023年8月28日
    079
  • 用python为心爱的人制作520照片墙,已成功做出效果图

    马上又要进入一年一度的520了,作为一个地地道道的程序猿心里慌得一批。除了吃饭买礼物看电影好像就没有更多的想法了,于是想想将女友从以前到现在的所有照片整理了一下准备制作一个前所未有…

    Python 2023年11月2日
    050
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球