0.背景
背景:成熟的项目体系或架构中,一定是多个项目或模块在线上同时运行
缘由:解决公司实际业务接口自动化测试中跨项目请求联调
1.封装
"""
@Author: yl
@File: new_request.py
@Time: 2023/02/13 20:05:14
"""
import ujson
import logging
import requests
import warnings
import threading
from setting import app_cof
from requests import Response
from typing import Any, Literal, TypeVar
T = TypeVar("T")
requests.packages.urllib3.disable_warnings()
warnings.filterwarnings('ignore')
def dictToUriStr(content: dict):
"""字典转为uri格式的字符串"""
if not content:
return ""
res: str = "?"
keys: list = list(content.keys())
for index, item in enumerate(content):
res += (item + "=")
res += str(content.get(item))
if index < len(keys) - 1:
res += "&"
return res
# noinspection DuplicatedCode
class RequestHandle:
"""requests请求封装"""
_instance: dict = {
}
lock = threading.Lock()
def __new__(cls, *args, **kwargs):
if cls._instance :
return cls._instance
with cls.lock:
if not cls.__instance:
cls.__instance = super().__new__