一、@allure.step的用法

  • 可以理解为我们编写测试用例中的每一步操作步骤,而在allure中表示对每个测试用例进行非常详细的步骤说明
  • 通过 @allure.step(),可以让测试用例在allure报告中显示更详细的测试过程

    示例代码
# -*- coding: utf-8 -*-
# @Time : 2020/12/12 8:34
# @Author : longrong.lang
# @FileName: test_allure.py
# @Software: PyCharm
# @Cnblogs :https://www.cnblogs.com/longronglang
import allure @allure.step("打开网站首页")
def open():
pass @allure.step("输入账号、密码")
def input_UsernameAndPassWord():
sendAndClickLogin("xiaoqiang", "1") @allure.step("输入账号、密码{arg1},{arg2},并点击登录")
def sendAndClickLogin(arg1, arg2):
pass @allure.step("验证登录过程")
def test_login():
open()
input_UsernameAndPassWord()

测试用例在allure的显示

小结

  • step(参数),参数就是标题,你传什么,在allure上的步骤名就显示什么
  • 支持位置参数和关键字参数 {arg1},{arg2},可参考报告中“ 输入账号、密码'xiaoqiang','1',并点击登录”处,如果函数的参数没有匹配成功就会报错

二、allure.attach的用法

作用: allure报告还支持显示许多不同类型的附件,可以补充测试结果;可根据自身情况进行调整

语法: allure.attach(body, name, attachment_type, extension)

参数列表

body:要显示的内容(附件)

name:附件名字

attachment_type:附件类型,是 allure.attachment_type 里面的其中一种

extension:附件的扩展名(比较少用)

allure.attachment_type提供了哪些附件类型?

语法二: allure.attach.file(source, name, attachment_type, extension)

source:文件路径,相当于传一个文件

示例代码如下:

# 添加附件案例
def test_attachments():
# 在测试报告中画了一个html页面
allure.attach('<head></head><body><strong>HTML页面,HelloWorld!</strong> </body>', 'Attach with HTML type', allure.attachment_type.HTML)
# 添加一个html附件
allure.attach.file('./report.html', attachment_type=allure.attachment_type.HTML)
# 添加一个图片附件
allure.attach.file('./demo.jpg', attachment_type=allure.attachment_type.JPG)

在allure报告中展示如下:

Pytest学习(20)- allure之@allure.step()、allure.attach的详细使用的更多相关文章

  1. Pytest 学习(二十五)- allure 命令行参数【转】

    先看看 allure 命令的帮助文档 cmd 敲 allure -h allure 命令的语法格式 allure [options] [command] [command options] optio ...

  2. Pytest 学习(二十七)- Jenkins+Allure+Pytest的持续集成

    一.配置 allure 环境变量 1.下载 allure是一个命令行工具,可以去 github 下载最新版:https://github.com/allure-framework/allure2/re ...

  3. Pytest系列(20)- allure结合pytest,allure.step()、allure.attach的详细使用

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 allure除了支持pyte ...

  4. Pytest 系列(28)- 参数化 parametrize + @allure.title() 动态生成标题

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 参数化 @pytest.ma ...

  5. Pytest系列(23)- allure打标记,@allure.feature()、@allure.story()、@allure.severity()的详细使用

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 前面几篇文章主要介绍了all ...

  6. Pytest 系列(29)- 详解 allure.dynamic 动态生成功能

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 @allure.title  ...

  7. Pytest学习笔记10-生成html报告

    前言 在pytest中,如何生成html测试报告呢,pytest提供了pytest-html插件,可以帮助我们生成测试报告,当然,如果希望生成更加精美的测试报告,我们还可以使用allure生成报告,下 ...

  8. Pytest学习(三) - setup和teardown的使用

    一.前言 从文章标题可以看出,就是初始化和释放的操作,根据我的java习惯来学习pytest,个人感觉没差太多,理解上也不是很难. 哦,对了,差点跑题了,这个框架是基于Python语言的,在学习的时候 ...

  9. OpenCV学习(20) grabcut分割算法

    http://www.cnblogs.com/mikewolf2002/p/3330390.html OpenCV学习(20) grabcut分割算法 在OpenCV中,实现了grabcut分割算法, ...

随机推荐

  1. pycharm远程编译

    1. 按照 https://www.cnblogs.com/xiongmao-cpp/p/7856596.html 完成配置 2. 使用步骤: (1)在本地新建代码文件或工程 (2)编写代码,完成后若 ...

  2. Linux_Python版本控制

    第1步:更新gcc,因为gcc版本太老会导致新版本python包编译不成功 复制代码代码如下: yum -y install gcc 系统会自动下载并安装或更新,等它自己结束 第2步:安装wget,这 ...

  3. C语言设计模式(命令模式)

    #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) typedef int (*parse_func)(const char *data,size_t len ...

  4. Java-Annotation的一种用法(消除代码中冗余的if/else或switch语句)

    Java-Annotation的一种用法(消除代码中冗余的if/else或switch语句) 1.冗余的if/else或switch ​ 有没有朋友写过以下的代码结构,大量的if/esle判断,来选择 ...

  5. 攻克solo第七课(Randy Rhoads风格)

    本期文章,笔者将通过Guitar Pro 7吉他软件跟大家分享一下Randy Rhoads的solo句子. 相信很多精研电吉他的朋友都会听过这个一手把Ozzy Osbourne从离开黑色安息日乐队的深 ...

  6. Tuxera Disk Manager轻松解决硬盘格式转换问题

    生活中经常会遇到硬盘格式转换的问题,很多小伙伴都不知道怎么进行操作,特别是Mac小白们.今天,小编想要给不熟悉Mac系统的小伙伴推荐一款专业且高效的磁盘管理工具--Tuxera NTFS,可以帮助我们 ...

  7. 浅谈 STL

    简介 STL是Standard Template Library的简称,中文名标准模板库,从根本上说,STL是一些"容器"的集合,这些"容器"有list,vec ...

  8. Codeforces Round #660 (Div. 2) A、B、C题解

    A. Captain Flint and Crew Recruitment #构造 题目链接 题意 定义一类正整数,能够被\(p*q\)表示,其中\(p.q(1<p<q)\)均为素数,称之 ...

  9. k8s集群部署rabbitmq集群

    1.构建rabbitmq镜像 RabbitMQ提供了一个Autocluster插件,可以自动创建RabbitMQ集群.下面我们将基于RabbitMQ的官方docker镜像,添加这个autocluste ...

  10. 【JVM】jdk1.8移除方法区与metaspace

    转载:https://blog.csdn.net/aa747604141/article/details/52673582 https://www.jianshu.com/p/a6f19189ec62