栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python自动化测试框架

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python自动化测试框架





access_token = ""       # 类变量

    # 获取鉴权码
    def test_get_token(self):
        url = 'https://api.weixin.qq.com/cgi-bin/token'
        datas = {
            "grantz_type" : "client_credential",
            "appid" : "wx74a8627810cfa308",
            "secret":"e40a02f9d79a8097df497e6aaf93ab80"
        }
        res = requests.get(url=url, params=datas)
        result = res.json()
        TestApi.access_token = result['access_token']

    def test_edit_flag(self):
        url="https://api.weixin.qq.com/cgi-bin/tag/upate?access_token="+TestApi.access_token
        datas={"tag": {"id":123, "name":"广东人"}}
        res = requests.post(url=url, json=datas)
        print(res.json())

#   文件上传, 以 files 的格式上传
    def test_file_upload(self):
        url="https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token="+TestApi.access_token
        datas = {
            "media": open("", mode="rb",)
        }
        res = SendRequest().all_send_request(method="post", url=url, files=datas)
        # res = requests.post(url=url, files=datas)
        print(res.json())









代码:

在这里插入代码片import pytest
import yaml

def read_yaml():
    return ["宝", "贝", "宝贝"]

# scope :{"function", "class"}
# autouse设置为false, 则不进行前后设置
# autouse设置为Ture,自动在类的前后进行设置,类似与setUpClass()...
# 一般写用来链接数据库的操作
# @pytest.fixture(scope="function", autouse=True)
@pytest.fixture(scope="function", autouse=False, params=read_yaml(), ids=['b1', 'bf','xy'], name="ea")
def exe_assert(request):    # 固定格式,利用request来接收params返回来的列表
    print("在用例之前执行:查询数据库用于断言")
    yield request.param
    print("在用例之后执行:查询书库库")

# @pytest.mark.usefixtures("exe_assert")          # 手动调用类的前后设置
class TestLogin:
    def test_login(self):
        print("登录接口")

    # def test_register(self, exe_assert):
    def test_register(self, ea):
        # print("注册接口" + exe_assert)
        print("注册接口:  " + ea)
        print("注册接口")

    def test_test(self):
        print("测试接口")

结果:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1025548.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号