当前位置:网站首页>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 )
边栏推荐
- Keil compilation code of CY7C68013A
- Thinkphp Kernel wo system source Commercial Open source multi - user + multi - Customer Service + SMS + email notification
- geotrust ov多域名ssl證書一年兩千一百元包含幾個域名?
- Lm09 Fisher inverse transform inversion mesh strategy
- How much can a job hopping increase? Today, I saw the ceiling of job hopping.
- Cannot activate CONDA virtual environment in vscode
- Social media search engine optimization and its importance
- How to recover deleted data in disk
- Pytorch---使用Pytorch进行图像定位
- Deep understanding of lambda expressions
猜你喜欢

C language practice - number guessing game

Embedded-c language-8-character pointer array / large program implementation

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

One click generation and conversion of markdown directory to word format

Shenzhen will speed up the cultivation of ecology to build a global "Hongmeng Oula city", with a maximum subsidy of 10million yuan for excellent projects

Win10 disk management compressed volume cannot be started

记录一次Unity 2020.3.31f1的bug

Alibaba cloud polkit pkexec local rights lifting vulnerability

Gin framework learning code

万卷共知,一书一页总关情,TVP读书会带你突围阅读迷障!
随机推荐
Let genuine SMS pressure measurement open source code
6.30年终小结,学生时代结束
Pytorch-Yolov5从0运行Bug解决:
C language practice - binary search (half search)
Free drawing software recommended - draw io
Change deepin to Alibaba image source
Pytorch---使用Pytorch进行鸟类的预测
LeetCode-归并排序链表
Online incremental migration of DM database
DJB Hash
Introduction to Luogu 3 [circular structure] problem list solution
Major domestic quantitative trading platforms
Common errors of dmrman offline backup
Pytoch --- use pytoch to realize u-net semantic segmentation
[Yu Yue education] autumn 2021 reference materials of Tongji University
geotrust ov多域名ssl证书一年两千一百元包含几个域名?
二叉树解题(二)
Federal learning: dividing non IID samples according to Dirichlet distribution
Markdown edit syntax
Learn BeanShell before you dare to say you know JMeter