当前位置:网站首页>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 )
边栏推荐
- 开源与安全的“冰与火之歌”
- Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
- Unity tips - draw aiming Center
- 当前系统缺少NTFS格式转换器(convert.exe)
- Smart street lamp based on stm32+ Huawei cloud IOT design
- 【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
- scratch疫情隔离和核酸检测模拟 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
- 02 personal developed products and promotion - SMS platform
- Grafana 9 is officially released, which is easier to use and more cool!
- 视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
猜你喜欢

视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
![[ASM] introduction and use of bytecode operation classwriter class](/img/0b/87c9851e577df8dcf8198a272b81bd.png)
[ASM] introduction and use of bytecode operation classwriter class

OliveTin能在网页上安全运行shell命令(上)

node の SQLite

The solution that flutterweb browser cannot be rolled back after refreshing

中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障

04 products and promotion developed by individuals - data push tool

Pytorch extract middle layer features?

Unity粒子特效系列-闪星星的宝箱

分布式不来点网关都说不过去
随机推荐
BearPi-HM_ Nano development environment
sql语句优化,order by desc速度优化
Flink analysis (II): analysis of backpressure mechanism
Easy introduction to SQL (1): addition, deletion, modification and simple query
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
Example of batch update statement combining update and inner join in SQL Server
开源与安全的“冰与火之歌”
Development and practice of lightweight planning service tools
C version selenium operation chrome full screen mode display (F11)
传统家装有落差,VR全景家装让你体验新房落成效果
【ASM】字节码操作 ClassWriter 类介绍与使用
Hongmeng introduction and development environment construction
Solid principle
Smart street lamp based on stm32+ Huawei cloud IOT design
基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
Essai de pénétration du Code à distance - essai du module b
Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
The solution that flutterweb browser cannot be rolled back after refreshing
SQL statement optimization, order by desc speed optimization
Pytorch extract middle layer features?