当前位置:网站首页>Pytest learning notes (12) -allure feature · @allure Step () and allure attach
Pytest learning notes (12) -allure feature · @allure Step () and allure attach
2022-07-03 01:29:00 【_ Li Sheng】
allure.step() and allure.attach
Preface
allure In addition to supporting common pytest Function outside ( xfails、fixture、skips and skipif、parametrize), It also has some powerful and practical functions .
This is mainly about step and attach function , You can set test steps and add attachments to the report .
@allure.step()
- Allure The most important aspect of the report is that it allows a very detailed step description of the invocation of each test case
- adopt
@allure.step
Decorator to achieve - It can be stored outside your test , And import only when needed
- Step Methods can have nested structures of any depth
demo Code
# __File__ = test_01.py
import allure
from .steps import imported_step
@allure.step("step-1")
def passing_step():
pass
@allure.step("step-2")
def step_with_nested_steps():
nested_step()
@allure.step("step-3")
def nested_step():
nested_step_with_arguments(1, 'abc')
@allure.step("step-4")
def nested_step_with_arguments(arg1, arg2):
pass
def test_with_imported_step():
passing_step()
imported_step()
def test_with_nested_steps():
passing_step()
step_with_nested_steps()
The results are as follows :
Use summary
- Parameters :title, Express step The name of , It can be directly displayed in the test report
- characteristic : You can nest , It can also be called externally
- Use scenarios : It is mainly used for the organization of scenario use cases , Use multiple function point use case groups to synthesize scenario use cases ( Allow external use cases )
allure.attach
- function : Test reports can display many different types of attachments , These accessories can supplement the test 、 Step or fixture result
Parameter Introduction
- usage 1:allure.attach(body, name, attachment_type, extension), The parameters are as follows :
- body: To write the original contents of the attachment
- name: The attachment of
- attachment_type:allure.attachment_type One type
- extension: Extension of the file
- usage 2:allure.attach.file(source, name, attachment_type, extension), Parameters :
- source: File path ( character string )
- ( Other parameters are the same )
usage 1 Used when there are no ready-made attachments you want to import , Add and display it in the test report
usage 2 It is mainly used for existing corresponding attachments , You can use path import directly , Show it in the test report
Code up
establish test_01.py
file , The contents are as follows :
import allure
import pytest
@pytest.fixture
def attach_file_in_module_scope_fixture_with_finalizer(request):
allure.attach(' stay fixture Add a txt The attachment ', 'fixture Front attachment ', allure.attachment_type.TEXT)
def finalizer_module_scope_fixture():
allure.attach(' stay fixture Add a txt The attachment ', 'fixture Rear attachment ',
allure.attachment_type.TEXT)
request.addfinalizer(finalizer_module_scope_fixture)
def test_with_attachments_in_fixture_and_finalizer(attach_file_in_module_scope_fixture_with_finalizer):
pass
def test_multiple_attachments():
allure.attach.file('chestnut_1f330.png', attachment_type=allure.attachment_type.PNG)
allure.attach.file('allure_report.html', attachment_type=allure.attachment_type.HTML)
allure.attach('<head></head><body> One HTML page </body>', 'Attach with HTML type', allure.attachment_type.HTML)
Check the running results as follows :
You can see the front and rear txt Attachment above .
You can see the use of attach() Insert pictures and HTML Accessories and use attach.file() Import an existing HTML.
边栏推荐
- 看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9
- [my advanced journey of OpenGL learning] collation of Euler angle, rotation order, rotation matrix, quaternion and other knowledge
- [C language] detailed explanation of pointer and array written test questions
- 产业互联网的产业范畴足够大 消费互联网时代仅是一个局限在互联网行业的存在
- leetcode:701. Insertion in binary search tree [BST insertion]
- d. LDC build shared library
- 每日一题之干草堆的移动
- Work experience of a hard pressed programmer
- Esp32 simple speed message test of ros2 (limit frequency)
- [androd] module dependency replacement of gradle's usage skills
猜你喜欢
[C language] detailed explanation of pointer and array written test questions
Cut point of undirected graph
一位苦逼程序员的找工作经历
每日一题之干草堆的移动
软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
Arduino DY-SV17F自动语音播报
Excel calculates the difference between time and date and converts it into minutes
攻克哈希的基本概念与实现
[技术发展-23]:DSP在未来融合网络中的应用
leetcode 6103 — 从树中删除边的最小分数
随机推荐
英语常用词汇
Androd gradle's substitution of its use module dependency
Niu Ke swipes questions and clocks in
2022 coal mine gas drainage examination question bank and coal mine gas drainage examination questions and analysis
Mongodb common commands of mongodb series
JDBC courses
强化学习 Q-learning 实例详解
Esp32 simple speed message test of ros2 (limit frequency)
信息熵的基础
Dotconnect for PostgreSQL data provider
tp6快速安装使用MongoDB实现增删改查
[shutter] animation animation (the core class of shutter animation | animation | curvedanimation | animationcontroller | tween)
ThinkPHP+Redis实现简单抽奖
[self management] time, energy and habit management
MySQL --- 数据库查询 - 条件查询
Basic remote connection tool xshell
给你一个可能存在 重复 元素值的数组 numbers ,它原来是一个升序排列的数组,并按上述情形进行了一次旋转。请返回旋转数组的最小元素。【剑指Offer】
leetcode刷题_两数之和 II - 输入有序数组
【C语言】指针与数组笔试题详解
Leetcode 2097 - Legal rearrangement of pairs