当前位置:网站首页>Getting started with pytest ----- test case pre post, firmware
Getting started with pytest ----- test case pre post, firmware
2022-07-06 17:49:00 【Peng Yuyan in the testing industry】
1、 Back and forth
The so-called pre post , Is similar to unittest
In the framework setup
and teardown
—— Open the browser before executing the use case ( In front of ), Close the browser after execution ( After ). for example :
The printed part of the code above is setup
、setup_class
、teardown
、teardown_class
Description of each method
But if there is another file , These operations are also required 【 such as ui To automate each use case, open the browser and execute 】 We need to encapsulate these common methods . notes : Public Library , Customarily, it will be defined as common
We have a new one called common
Of package
, Then create... In it common_util
file , The new class CommonUtil
Cut public methods into this class
Then other classes only need to inherit this class 【python Basic knowledge of 】
The above is what we learn unittest
Time thinking . But now if there is The new demand : Only one use case requires preconditions , The rest don't need . What should I do at this time ? It seems that this method of inheritance is not so flexible .
This leads to fixture
Come on Realize partial pre post
grammar :@pytest.fixture()
Parameters :
scope -- Scope
function: Before and after the function
class: class After and before execution
package/session: The whole project session After and before execution
autouse -- Automatic execution
Default :False; If instead True, You don't need to call , In the corresponding scope, it will automatically execute
...
Let's start with a popular example :
hold CommonUtil
The code inside is commented out , direct pass, Let it no longer take effect
Then modify the test file :
After execution, you can see , Only test_py
Method is called exe_sql
Method .
Add the second parameter autouse
The value is True
, After execution, you can see that all use cases reference exe_sql
Method
up to now , All are “ Before ” perform ,“ after ” How to do it?
“ after ” Use yield
Execution results :
notes : In a file There can be multiple fixture
, You can add as many as you need
however fixture
This firmware Only effective in the current document , Other documents will not take effect , If other files are to take effect, configure conftest.py
The file .
And there are many other parameters , We'll talk about these tomorrow .
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 )
边栏推荐
- FlutterWeb瀏覽器刷新後無法回退的解决方案
- How to use scroll bars to dynamically adjust parameters in opencv
- Unity小技巧 - 绘制瞄准准心
- Nodejs 开发者路线图 2022 零基础学习指南
- Optimization of middle alignment of loading style of device player in easycvr electronic map
- 虚拟机启动提示Probing EDD (edd=off to disable)错误
- About selenium starting Chrome browser flash back
- Huawei certified cloud computing hica
- Selenium test of automatic answer runs directly in the browser, just like real users.
- connection reset by peer
猜你喜欢
【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
PyTorch 提取中间层特征?
Zen integration nails, bugs, needs, etc. are reminded by nails
Virtual machine startup prompt probing EDD (edd=off to disable) error
After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
node の SQLite
[translation] principle analysis of X Window Manager (I)
Pytorch extract middle layer features?
分布式(一致性协议)之领导人选举( DotNext.Net.Cluster 实现Raft 选举 )
分布式不来点网关都说不过去
随机推荐
TCP连接不止用TCP协议沟通
JMeter interface test response data garbled
Uipath browser performs actions in the new tab
Xin'an Second Edition: Chapter 12 network security audit technology principle and application learning notes
分布式不来点网关都说不过去
当前系统缺少NTFS格式转换器(convert.exe)
Remote code execution penetration test - B module test
面试突击63:MySQL 中如何去重?
How to output special symbols in shell
Nodejs 开发者路线图 2022 零基础学习指南
It doesn't make sense without a distributed gateway
2022年大厂Android面试题汇总(一)(含答案)
虚拟机启动提示Probing EDD (edd=off to disable)错误
The art of Engineering (1): try to package things that do not need to be exposed
Concept and basic knowledge of network layering
Flink parsing (III): memory management
yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
Alertmanager sends the alarm email and specifies it as the Alibaba mailbox of the company
EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
Shell input a string of numbers to determine whether it is a mobile phone number