美文网首页
7. 框架优化-1

7. 框架优化-1

作者: 薛东弗斯 | 来源:发表于2024-02-13 10:18 被阅读0次

pytest读取.ini文件

# config/setting.ini
[host]
api_sit_url = https://api.binstd.com
# utils/read_ini.py
import configparser
import os

current_path = os.path.realpath(__file__)
parent_path = os.path.dirname(current_path)
path = os.path.join(os.path.dirname(parent_path), "config", "setting.ini")


def read_ini():
    config = configparser.ConfigParser()
    config.read(path, encoding='utf8')
    return config

get_ini = read_ini()
# print(read_ini()['host']['api_sit_url'])
## https://api.binstd.com

将read_ini 与 read_data整合,类方法实现

project > config > setting.ini
[host]
api_sit_url = https://api.binstd.com
# project > data > data.yaml
mobile: {shouji: 13456759012,appkey: 0c818521d38759e1}
# project > utils > read_test.py
import yaml
import configparser
import os

current_path = os.path.realpath(__file__)
parent_path = os.path.dirname(current_path)
data_path = os.path.join(os.path.dirname(parent_path), "data", "data.yaml")
ini_path = os.path.join(os.path.dirname(parent_path), "config", "setting.ini")


class FileRead:
    def __init__(self):
        self.data_path = data_path
        self.ini_path = ini_path

    def read_data(self):
        f = open(self.data_path, encoding="utf8")
        data = yaml.safe_load(f)
        return data

    def read_ini(self):
        config = configparser.ConfigParser()
        config.read(self.ini_path, encoding='utf8')
        return config


base_data = FileRead()
# project > test_read > test_read.py
import requests
import pytest
from utils.read_test import base_data

url = base_data.read_ini()['host']['api_sit_url']


def test_mobile():
    param = base_data.read_data()['mobile']
    r = requests.get(url + "/shouji/query",
                     params={"shouji": param['shouji'], "appkey": param['appkey']})
    print(r.status_code)
    print(r.json())


if __name__ == '__main__':
    pytest.main()
# Result
test_read.py 200
{'status': 0, 'msg': 'ok', 'result': {'shouji': '13456759012', 'province': '浙江', 'city': '杭州', 'company': '中国移动', 'cardtype': None, 'areacode': '0571'}}
.

Notepad++ download | SourceForge.net

相关文章

  • 1/7. 框架式写作

    分享者:秋叶大叔 为什么要学框架式写作 1、解决无话可写 孕妇效应 邻三月:写身边的人、事、自己的感悟、别人的投稿...

  • EffectiveObjective-C2.0 笔记 - 第七部

    7. 系统框架 7.1 熟悉系统框架 1. 框架:将一系列代码封装成动态库,并在其中放入描述其接口的头文件。 平时...

  • C语言小游戏教程P7

    7. 界面美化 这篇教程就要接近尾声了,今天我们来优化一下用户体验 优化点1:输出血量 打游戏不看血怎行? 不多说...

  • 接口测试框架(三)-框架优化

    接口测试框架(三)-框架优化

  • 优化方法总结

    优化算法框架 神经网络模型中有多种优化算法,优化算法的作用用来优化更新参数。对于优化算法而言,主要的框架如下。参数...

  • 优化算法matlab实现(二)框架编写

    1.编写框架的目的 在优化算法笔记(一)优化算法的介绍[https://www.jianshu.com/p/82d...

  • H5 Canvas2D API、绘制回字、走势图、圆饼、图片,变

    目录 1.API 2.回字 3.走势图 4.圆饼 5.图片 6.变换与环境 7.画布优化 1.API ...

  • 7.系统框架

    第47条 熟悉系统框架 第三方的framework并不是严格意义上的动态库,但系统的framework都是动态库 ...

  • 7.网络框架

    概念 retrofit、android-async-http、volley,帮你封装了具体的请求,线程切换以及数据...

  • 7. linux框架

    一个完整的linux内核一般由5部分组成,分为内存管理、进程管理、进程间通信、虚拟文件系统、网络接口1. linu...

网友评论

      本文标题:7. 框架优化-1

      本文链接:https://www.haomeiwen.com/subject/eyijadtx.html