当前位置:网站首页>Pytest learning ----- pytest Interface Association framework encapsulation of interface automation testing
Pytest learning ----- pytest Interface Association framework encapsulation of interface automation testing
2022-07-02 04:42:00 【Peng Yuyan in the testing industry】
In general , We're going through one yaml File association implementation
Create a new file in the root directory yaml, Through the above conftest.py File to update global variables :
1. First, you need to create a read 、 write in 、 eliminate yaml File tool class
as follows :
import os
import yaml
class YamlUnit:
def readAllYaml(self):
with open(os.getcwd() + "/extract.yml", mode='r', encoding='utf-8') as f:
value = yaml.load(stream=f, Loader=yaml.FullLoader)
return value
def readKeyYaml(self,key):
with open(os.getcwd() + "/extract.yml", mode='r', encoding='utf-8') as f:
value = yaml.load(stream=f, Loader=yaml.FullLoader)
return value[key]
def writeYaml(self, data):
with open(os.getcwd() + "/extract.yml", mode='w', encoding='utf-8') as f:
print(os.getcwd() + "/extract.yml")
value = yaml.dump(data=data, stream=f, allow_unicode=True)
def deleteYaml(self):
with open(os.getcwd()+"/extract.yml",mode="w",encoding='utf-8') as f:
f.truncate()
2. coordination conftest.py file + fixture Implement global shared calls
# 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()
@pytest.fixture(scope="session", autouse=True)
def get_token():
token = ''; # obtain token Code request for
return token
3. When calling, just pass in the method function name
Such as : Before using the following functions, you need to connect to the database , Just incoming conftest.py In the document conn_getbase The function name is just
def test_Login(self,conn_getbase):
# post request
url = "xxxxxxx"
# Parameters
data = {
"captcha": "[email protected]#2019",
"checkKey": 1637811815838,
"password": "123456",
"remember_me": 1,
"username": "admin"
}
rep = requests.request('post', url, json=data)
statues = rep.json()["success"]
message = rep.json()["message"]
if statues:
print(message )
else:
raise Exception(message) 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 )
边栏推荐
- 记录一次Unity 2020.3.31f1的bug
- Thinkphp內核工單系統源碼商業開源版 多用戶+多客服+短信+郵件通知
- [Yu Yue education] autumn 2021 reference materials of Tongji University
- Markdown edit syntax
- Idea autoguide package and autodelete package Settings
- 6.30年终小结,学生时代结束
- Unity particle Foundation
- How do I interview for a successful software testing position? If you want to get a high salary, you must see the offer
- VMware installation win10 reports an error: operating system not found
- Pytoch yolov5 runs bug solution from 0:
猜你喜欢

Deep understanding of lambda expressions

CY7C68013A之keil编译代码

Rhcsa --- work on the fourth day

记录一次Unity 2020.3.31f1的bug

AcrelEMS高速公路微电网能效管理平台与智能照明解决方案智慧点亮隧道

Ognl和EL表达式以及内存马的安全研究

Pytorch---使用Pytorch实现U-Net进行语义分割

How much can a job hopping increase? Today, I saw the ceiling of job hopping.

LeetCode-归并排序链表

Several methods of capturing packets under CS framework
随机推荐
office_ Delete the last page of word (the seemingly blank page)
Unity particle Foundation
unable to execute xxx. SH: operation not permitted
Pytoch --- use pytoch for image positioning
Message mechanism -- message processing
C language guessing numbers game
Introduction to Luogu 3 [circular structure] problem list solution
What are the rules and trading hours of agricultural futures contracts? How much is the handling fee deposit?
缓存一致性解决方案——改数据时如何保证缓存和数据库中数据的一致性
Arbre binaire pour résoudre le problème (2)
Cache consistency solution - how to ensure the consistency between the cache and the data in the database when changing data
Play with concurrency: what's the use of interruptedexception?
第十六周作业
Comp 250 parsing
UNET deployment based on deepstream
Yolov5 network modification tutorial (modify the backbone to efficientnet, mobilenet3, regnet, etc.)
Vmware安装win10报错:operating system not found
Websites that it people often visit
DMA Porter
Thinkphp Kernel wo system source Commercial Open source multi - user + multi - Customer Service + SMS + email notification