当前位置:网站首页>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 )
边栏推荐
- A summary of common interview questions in 2022, including 25 technology stacks, has helped me successfully get an offer from Tencent
- [improvement class] st table to solve the interval maximum value problem [2]
- Unit testing classic three questions: what, why, and how?
- oracle 存储过程与job任务设置
- Detailed process of DC-1 range construction and penetration practice (DC range Series)
- Markdown编辑语法
- Change deepin to Alibaba image source
- [Yu Yue education] autumn 2021 reference materials of Tongji University
- Typescript function details
- Starting from the classification of database, I understand the map database
猜你喜欢
C language practice - number guessing game
Win10 disk management compressed volume cannot be started
DC-1靶场搭建及渗透实战详细过程(DC靶场系列)
Tawang food industry insight | current situation, consumption data and trend analysis of domestic infant complementary food market
Thinkphp内核工单系统源码商业开源版 多用户+多客服+短信+邮件通知
6月书讯 | 9本新书上市,阵容强大,闭眼入!
Embedded-c language-8-character pointer array / large program implementation
Embedded-c language-9-makefile/ structure / Consortium
Mapping location after kotlin confusion
Starting from the classification of database, I understand the map database
随机推荐
Why can't you remember when reading? Why can't you remember- My technology learning methodology
VMware installation win10 reports an error: operating system not found
6月书讯 | 9本新书上市,阵容强大,闭眼入!
Beginner crawler - biqu Pavilion crawler
缓存一致性解决方案——改数据时如何保证缓存和数据库中数据的一致性
Homework of the 16th week
Gin framework learning code
How to write a client-side technical solution
Comp 250 parsing
The solution to the complexity brought by lambda expression
Tawang food industry insight | current situation, consumption data and trend analysis of domestic infant complementary food market
Play with concurrency: draw a thread state transition diagram
深圳打造全球“鸿蒙欧拉之城”将加快培育生态,优秀项目最高资助 1000 万元
Free drawing software recommended - draw io
Leetcode- insert and sort the linked list
面试会问的 Promise.all()
C language practice - binary search (half search)
Pytoch --- use pytoch to realize u-net semantic segmentation
TypeScript函数详解
geotrust ov多域名ssl证书一年两千一百元包含几个域名?