当前位置:网站首页>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 )
边栏推荐
- How to submit data through post
- Manifest of SAP ui5 framework json
- Alibaba brand data bank: introduction to the most complete data bank
- [translation] principle analysis of X Window Manager (I)
- 78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
- Flet教程之 13 ListView最常用的滚动控件 基础入门(教程含源码)
- Solrcloud related commands
- Xin'an Second Edition: Chapter 26 big data security demand analysis and security protection engineering learning notes
- 2022年大厂Android面试题汇总(一)(含答案)
- Optimization of middle alignment of loading style of device player in easycvr electronic map
猜你喜欢
Interpretation of Flink source code (II): Interpretation of jobgraph source code
Huawei certified cloud computing hica
[rapid environment construction] openharmony 10 minute tutorial (cub pie)
yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
JMeter interface test response data garbled
Solr appears write Lock, solrexception: could not get leader props in the log
Grafana 9 正式发布,更易用,更酷炫了!
BearPi-HM_ Nano development environment
【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符
78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
随机推荐
EasyCVR授权到期页面无法登录,该如何解决?
OliveTin能在网页上安全运行shell命令(上)
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
Binary search strategy
The art of Engineering
sql语句优化,order by desc速度优化
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
Remote code execution penetration test - B module test
Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
Precipitated database operation class - version C (SQL Server)
[rapid environment construction] openharmony 10 minute tutorial (cub pie)
C # nanoframework lighting and key esp32
SAP UI5 框架的 manifest.json
[introduction to MySQL] third, common data types in MySQL
node の SQLite
Summary of Android interview questions of Dachang in 2022 (I) (including answers)
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
面试突击62:group by 有哪些注意事项?
Xin'an Second Edition: Chapter 25 mobile application security requirements analysis and security protection engineering learning notes