python动态断言

本文介绍了一种通用的Python动态断言方法,该方法适用于不同业务场景,支持值对比、键值对以及正则表达式的断言,具体实现和使用方法文中详细阐述。
摘要由CSDN通过智能技术生成

根据业务场景,本人写了一个通用的动态断言方法,支持value,{key:value},{key:正则表达式},方法如下

# coding=utf-8
import re
from app_execution.allFunction import allFunction


class TestResult(object):
    def testcase(self, result, assertdata):  # 根据respcode和message正则断言
        testresult ='0'
        if (result == None or assertdata == None):  # 如果断言规则是空的
            testresult = '1'
        if isinstance(assertdata, str):  # 如果断言规则是字符串
            assert_respcode_result = re.search(assertdata, result['respCode'], re.I | re.M)
            assert_message_result = re.search(assertdata, result['message'], re.I | re.M)
            if assert_respcode_result or assert_message_result:
                testresult = '1'
            else:
                testresult = TestResult().assert_key(assertdata, result)
        return testresult

    def assert_key(self, assert_data, result):#递归断言
        testresult &
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值