当前位置:网站首页>Getting started with pytest -- description of fixture parameters
Getting started with pytest -- description of fixture parameters
2022-07-02 04:42:00 【Peng Yuyan in the testing industry】
fixture Implement pre post
Parameters
scope -- Scope
function: function / Methods are executed before and after
The manual call method is to add fixture The name of
class: class After and before execution
The way to manually call is to add @pytest.mark.usefixtures(" Method name ") Decorator
package/session: The whole project session After and before execution .
When session It only works on one .py File is equivalent to module
Generally, they will combine conftest.py File to implement
autouse -- Automatic execution
Default :False; If instead True, You don't need to call , In the corresponding scope, it will automatically execute
params -- Realize parameterization ( Data driven )
ids -- Parameters , It has to be with params Use it together , Alias the parameter
name -- to fixture names
yield Data can be returned , similar return, however return You can't connect code later , and yield Later, you can continue to write other code . So in “ After ” In operation , We are all used to yield.
When scope The value of is class,autouse The value of is False when , How to call fixture:
@pytest.mark.usefixtures(" Method name ")

params For parameterization
For example, a use case needs to be used separately 3 Different data ( Equivalence classes and boundary values ) To test , If a use case code is written three times, it's a little stupid , Use this time params This parameter can

explain :
1、params=read_yaml() --params= Method name (), call
2、exe_sql(request) Be careful , In brackets is request That's what the regulations say , No why?
3、request.param Call through read_yaml() Method to get the data , It is required to write like this , The above parameter is params, Here is param, It is required to write like this
4、exe_sql I used to print here print(request.param) Look at the , And then yield Of . To illustrate , Is to realize parameterization ( Data driven ), To emphasize directly, pass yield Method can pass the obtained value as a parameter to other methods
5、test_api() Method reference fixture, Pass in the method fixture Modified method name
Execution results :

You can see , Use case 2 is executed three times with test data .
ids Not to be used alone , It has to be with params Use it together , The function is to alias the parameter
Look at the execution result above

If your data is too long , Then the display here will be messy , At this time, you can use ids This parameter

Execution results :

name The function is to give fixture names
Up here we use fixture The method of decoration is exe_sql, If this method is long or you don't want to call it, call it by this name , You can use it name to fixture The method of modification is to change the name

Be careful : When you give fixture Method of decoration (exe_sql()) Yes name After changing the name of the parameter , When calling use cases, you should use your changed name (db), Use the original method name (exe_sql) It's a mistake , Because I can't find it .
The following is the supporting information , For doing 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you !
Last : It can be in the official account : Programmer Xiaohao ! Get a free copy of 216 Page software testing engineer interview guide document information . And the corresponding video learning tutorial is free to share !, It includes basic knowledge 、Linux necessary 、Shell、 The principles of the Internet 、Mysql database 、 Special topic of bag capturing tools 、 Interface testing tool 、 Test advanced -Python Programming 、Web automated testing 、APP automated testing 、 Interface automation testing 、 Testing advanced continuous integration 、 Test architecture development test framework 、 Performance testing 、 Safety test, etc. .
If my blog helps you 、 If you like my blog content , please “ give the thumbs-up ” “ Comment on ” “ Collection ” One button, three links ! Friends who like software testing , You can join our testing technology exchange group :779450660 There are various software testing resources and technical discussions )
边栏推荐
- A summary of common interview questions in 2022, including 25 technology stacks, has helped me successfully get an offer from Tencent
- Alibaba cloud polkit pkexec local rights lifting vulnerability
- CorelDRAW Graphics Suite2022免费图形设计软件
- One click generation and conversion of markdown directory to word format
- Idea automatic package import and automatic package deletion settings
- 汇编语言中的标志位:CF、PF、AF、ZF、SF、TF、IF、DF、OF
- Social media search engine optimization and its importance
- 面试会问的 Promise.all()
- 阿里云polkit pkexec 本地提权漏洞
- Ruby replaces gem Alibaba image
猜你喜欢

Exposure X8 Standard Version picture post filter PS, LR and other software plug-ins

Leetcode- insert and sort the linked list
![[C language] basic learning notes](/img/d2/1aeb2d37d97b9cfe4b21aa3ac37645.png)
[C language] basic learning notes

Detailed process of DC-1 range construction and penetration practice (DC range Series)
![[Yu Yue education] autumn 2021 reference materials of Tongji University](/img/50/5136359b89a5d047fe648637643ad0.jpg)
[Yu Yue education] autumn 2021 reference materials of Tongji University

Mysql表insert中文变?号的问题解决办法

Shenzhen will speed up the cultivation of ecology to build a global "Hongmeng Oula city", with a maximum subsidy of 10million yuan for excellent projects

C language practice - binary search (half search)

DC-1靶场搭建及渗透实战详细过程(DC靶场系列)

The solution to the complexity brought by lambda expression
随机推荐
Exposure X8标准版图片后期滤镜PS、LR等软件的插件
Learn AI safety monitoring project from zero [attach detailed code]
Yolov5网络修改教程(将backbone修改为EfficientNet、MobileNet3、RegNet等)
正大留4的主账户信息汇总
Pit encountered in win11 pytorch GPU installation
Pytoch --- use pytoch for image positioning
Introduction to Luogu 3 [circular structure] problem list solution
二叉树解题(二)
汇编语言中的标志位:CF、PF、AF、ZF、SF、TF、IF、DF、OF
洛谷入门3【循环结构】题单题解
Mysql database learning
Ognl和EL表达式以及内存马的安全研究
A summary of common interview questions in 2022, including 25 technology stacks, has helped me successfully get an offer from Tencent
Mysql中常见的锁
What are the rules and trading hours of agricultural futures contracts? How much is the handling fee deposit?
Record the bug of unity 2020.3.31f1 once
oracle 存储过程与job任务设置
二叉树解题(一)
第十六周作业
Win10 disk management compressed volume cannot be started