当前位置:网站首页>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.stepDecorator 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.
边栏推荐
- Meituan dynamic thread pool practice ideas, open source
- Mathematical knowledge: step Nim game game game theory
- 什么是调。调的故事
- 不登陆或者登录解决oracle数据库账号被锁定。
- 2022 coal mine gas drainage examination question bank and coal mine gas drainage examination questions and analysis
- 數學知識:臺階-Nim遊戲—博弈論
- MySQL foundation 05 DML language
- MySQL基础用法02
- 【面试题】1369- 什么时候不能使用箭头函数?
- kivy教程之在 Kivy App 中使用 matplotlib 的示例
猜你喜欢

信息熵的基础

leetcode刷题_两数之和 II - 输入有序数组

MySQL

一比特苦逼程序員的找工作經曆

wirehark数据分析与取证A.pacapng

Database SQL language 01 where condition

Using tensorboard to visualize the model, data and training process

MySQL

【FPGA教程案例6】基于vivado核的双口RAM设计与实现

Give you an array numbers that may have duplicate element values. It was originally an array arranged in ascending order, and it was rotated once according to the above situation. Please return the sm
随机推荐
The industrial scope of industrial Internet is large enough. The era of consumer Internet is only a limited existence in the Internet industry
如今少年已归来,人间烟火气最抚凡人心 复工了~
Kivy tutorial how to create drop-down lists in Kivy
C application interface development foundation - form control (2) - MDI form
[interview question] 1369 when can't I use arrow function?
[fh-gfsk] fh-gfsk signal analysis and blind demodulation research
对非ts/js文件模块进行类型扩充
JDBC courses
【FPGA教程案例5】基于vivado核的ROM设计与实现
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
LDC Build Shared Library
Uniapp component -uni notice bar notice bar
Database SQL language 02 connection query
【FH-GFSK】FH-GFSK信号分析与盲解调研究
[day 29] given an integer, please find its factor number
Button wizard play strange learning - automatic return to the city route judgment
软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
Arduino dy-sv17f automatic voice broadcast
[Arduino experiment 17 L298N motor drive module]
测试右移:线上质量监控 ELK 实战