当前位置:网站首页>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浏览器刷新后无法回退的解决方案
- 微信小程序获取手机号
- PySpark算子处理空间数据全解析(5): 如何在PySpark里面使用空间运算接口
- Alibaba brand data bank: introduction to the most complete data bank
- Grafana 9 is officially released, which is easier to use and more cool!
- Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
- Flink parsing (III): memory management
- 视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
- 历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
- 全网最全tcpdump和Wireshark抓包实践
猜你喜欢
Grafana 9 is officially released, which is easier to use and more cool!
Grafana 9 正式发布,更易用,更酷炫了!
Vscode replaces commas, or specific characters with newlines
BearPi-HM_ Nano development board "flower protector" case
学 SQL 必须了解的 10 个高级概念
Flink analysis (II): analysis of backpressure mechanism
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
Display picture of DataGridView cell in C WinForm
Interview shock 62: what are the precautions for group by?
Automatic operation and maintenance sharp weapon ansible Foundation
随机推荐
[translation] principle analysis of X Window Manager (I)
Development and practice of lightweight planning service tools
EasyCVR授权到期页面无法登录,该如何解决?
Alibaba brand data bank: introduction to the most complete data bank
基于STM32+华为云IOT设计的智能路灯
Concept and basic knowledge of network layering
Spark accumulator and broadcast variables and beginners of sparksql
Kali2021 installation and basic configuration
Error: Publish of Process project to Orchestrator failed. The operation has timed out.
Single responsibility principle
Cool Lehman has a variety of AI digital human images to create a vr virtual exhibition hall with a sense of technology
Interpretation of Flink source code (II): Interpretation of jobgraph source code
Sqoop I have everything you want
How to use scroll bars to dynamically adjust parameters in opencv
Display picture of DataGridView cell in C WinForm
酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅
自动化运维利器ansible基础
OliveTin能在网页上安全运行shell命令(上)
Smart street lamp based on stm32+ Huawei cloud IOT design
全网最全tcpdump和Wireshark抓包实践