当前位置:网站首页>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 )
边栏推荐
- Interpretation of Flink source code (II): Interpretation of jobgraph source code
- OpenCV中如何使用滚动条动态调整参数
- 在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
- FlutterWeb瀏覽器刷新後無法回退的解决方案
- 一体化实时 HTAP 数据库 StoneDB,如何替换 MySQL 并实现近百倍性能提升
- 视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
- Flink parsing (III): memory management
- Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)
- Hongmeng introduction and development environment construction
- Remote code execution penetration test - B module test
猜你喜欢
There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
重磅!蚂蚁开源可信隐私计算框架“隐语”,主流技术灵活组装、开发者友好分层设计...
The problem of "syntax error" when uipath executes insert statement is solved
Reppoints: advanced order of deformable convolution
[ASM] introduction and use of bytecode operation classwriter class
面试突击63:MySQL 中如何去重?
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
Sqoop I have everything you want
Zen integration nails, bugs, needs, etc. are reminded by nails
Pytorch extract middle layer features?
随机推荐
The art of Engineering
Reppoints: advanced order of deformable convolution
After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
MySQL stored procedure
BearPi-HM_ Nano development board "flower protector" case
C # nanoframework lighting and key esp32
Grafana 9 is officially released, which is easier to use and more cool!
C WinForm series button easy to use
About selenium starting Chrome browser flash back
Unity particle special effects series - treasure chest of shining stars
微信小程序获取手机号
Debug xv6
【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
Spark calculation operator and some small details in liunx
Unity tips - draw aiming Center
scratch疫情隔离和核酸检测模拟 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
C version selenium operation chrome full screen mode display (F11)