当前位置:网站首页>Pytest learning ----- pytest confitest of interface automation test Py file details
Pytest learning ----- pytest confitest of interface automation test Py file details
2022-07-06 17:49:00 【Peng Yuyan in the testing industry】
One 、’conftest characteristic :
1、 Can span .py A file called , There are many. .py File call , Allowing conftest.py Only called once fixture, Or call multiple times fixture
2、conftest.py The same as the running use case pakage Next , And there are init.py file
3、 Unwanted import Import conftest.py,pytest The example will automatically identify the file , Put it under the root directory of the project and call the global directory , If you put it in one package Next , That's changing package Effective within , There can be multiple conftest.py
4、conftest.py The configuration script name is fixed , You can't change the name
5、conftest.py File cannot be imported by other files
6、 All test files in the same directory will be executed before running conftest.py file
Two 、’conftest usage :
conftest The practical application of the document needs to be combined with fixture To use ,fixture In the parameter scope Also applicable conftest in fixture Characteristics of , Here's another explanation
1、fixture Source details
1.fixture(scope='function',params=None,autouse=False,ids=None,name=None):
fixture There's a scope Parameters can be controlled fixture The scope of action of ,scope: There are four level parameters "function"( Default ),"class","module","session
2.params: An optional parameter list , It will result in multiple parameter calls fixture Function and all tests use it .
3.autouse: If True, Active for all tests fixture func You can see it . If False The display requires a reference to activate fixture
4.ids: Each string id A list of , Each string corresponds to params So they're the test ID Part of . If not provided ID They will come from params Automatic generation
5.name:fixture The name of . This defaults to the name of the decoration function . If fixture The first mock exam is used in defining its unified module. , Fixture function name will be requested fixture function arg shelter , One way to solve this problem is to decorate the function command "fixture_<fixturename>" And then use "@pytest.fixture(name='<fixturename>')".
2、fixture The scope of action of
fixture There's a scope Parameters can be controlled fixture The scope of action of :session>module>class>function
-function: Every function or method calls
-class: Each class is called once , There can be multiple methods in a class
-module: every last .py File call once , There are many more in this file function and class
-session: Multiple files are called once , Can span .py A file called , Every .py The document is module
function The default mode @pytest.fixture(scope='function') or @pytest.fixture()
3、conftest combination fixture Use
conftest in fixture Of scope Parameter is session, All tests .py Execute once before file execution
conftest in fixture Of scope Parameter is module, Every test .py The file will be executed once before execution conftest In the document fixture
conftest in fixture Of scope Parameter is class, The test class in each test file will be executed once before execution conftest In the document fixture
conftest in fixture Of scope Parameter is function, The test cases of all files will be executed once before execution conftest In the document fixture
3、 ... and 、conftest Application scenarios
1、 Each interface needs to share token
2、 Test case data to be shared by each interface
3、 Configuration information to be shared by each interface
# Realize partial pre
import pytest
from comment.yaml_unit import YamlUnit
@pytest.fixture(scope="function")
def conn_getbase():
print(" Successfully connected to database ")
yield
print(" Closing database succeeded ")
@pytest.fixture(scope="session", autouse=True)
def clear_yaml():
YamlUnit().deleteYaml()
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 )
边栏推荐
- 分布式不来点网关都说不过去
- Single responsibility principle
- pip install pyodbc : ERROR: Command errored out with exit status 1
- 传统家装有落差,VR全景家装让你体验新房落成效果
- How to submit data through post
- RepPoints:可形变卷积的进阶
- Cool Lehman has a variety of AI digital human images to create a vr virtual exhibition hall with a sense of technology
- Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
- Display picture of DataGridView cell in C WinForm
- connection reset by peer
猜你喜欢
The solution that flutterweb browser cannot be rolled back after refreshing
Development and practice of lightweight planning service tools
FlutterWeb浏览器刷新后无法回退的解决方案
[introduction to MySQL] the first sentence · first time in the "database" Mainland
Unity particle special effects series - treasure chest of shining stars
[getting started with MySQL] fourth, explore operators in MySQL with Kiko
JMeter interface test response data garbled
Distinguish between basic disk and dynamic disk RAID disk redundant array
04 products and promotion developed by individuals - data push tool
BearPi-HM_ Nano development board "flower protector" case
随机推荐
在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
Unity tips - draw aiming Center
78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
How uipath determines that an object is null
Interview shock 62: what are the precautions for group by?
EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
Summary of study notes for 2022 soft exam information security engineer preparation
node の SQLite
Vscode replaces commas, or specific characters with newlines
In terms of byte measurement with an annual salary of 30W, automated testing can be learned in this way
Interview assault 63: how to remove duplication in MySQL?
Flink parsing (III): memory management
Debug xv6
Optimization of middle alignment of loading style of device player in easycvr electronic map
[introduction to MySQL] third, common data types in MySQL
微信小程序获取手机号
当前系统缺少NTFS格式转换器(convert.exe)
Alertmanager sends the alarm email and specifies it as the Alibaba mailbox of the company