当前位置:网站首页>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 )
边栏推荐
- 二叉樹解題(二)
- Rhcsa --- work on the third day
- 正大美欧4的主账户关注什么数据?
- Pytorch-Yolov5從0運行Bug解决:
- Why can't you remember when reading? Why can't you remember- My technology learning methodology
- 初学爬虫-笔趣阁爬虫
- How much can a job hopping increase? Today, I saw the ceiling of job hopping.
- C语言猜数字游戏
- What methods should service define?
- DJB Hash
猜你喜欢

Pytoch --- use pytoch to predict birds

Ten thousand volumes are known to all, and one page of a book is always relevant. TVP reading club will take you through the reading puzzle!

Playing with concurrency: what are the ways of communication between threads?

Starting from the classification of database, I understand the map database

Embedded-c language-9-makefile/ structure / Consortium

What methods should service define?

How to recover deleted data in disk

解决:代理抛出异常错误

My first experience of shadowless cloud computer

Summary of main account information of zhengdaliu 4
随机推荐
Play with concurrency: what's the use of interruptedexception?
Federal learning: dividing non IID samples according to Dirichlet distribution
LeetCode-对链表进行插入排序
Shutdown procedure after 60
Mysql表insert中文变?号的问题解决办法
powershell_ View PowerShell function source code (environment variable / alias) / take function as parameter
DJB Hash
geotrust ov多域名ssl證書一年兩千一百元包含幾個域名?
Oracle stored procedure and job task setting
Three years of experience in Android development interview (I regret that I didn't get n+1, Android bottom development tutorial
Websites that it people often visit
Change deepin to Alibaba image source
6月书讯 | 9本新书上市,阵容强大,闭眼入!
Online incremental migration of DM database
cs架构下抓包的几种方法
第十六周作业
[C language] Dynamic Planning --- from entry to standing up
Pytorch yolov5 exécute la résolution de bogues à partir de 0:
Exposure X8标准版图片后期滤镜PS、LR等软件的插件
TypeScript函数详解