首页 > 编程语言 > 详细

python ddt 重写

时间:2018-06-03 18:12:24      阅读:274      评论:0      收藏:0      [点我收藏+]

对此方法重写

def mk_test_name(name, value, index=0):

 

重写前

index = "{0:0{1}}".format(index + 1, index_len)
    if not is_trivial(value):
        return "{0}_{1}".format(name, index)
    try:
        value = str(value)
    except UnicodeEncodeError:
        # fallback for python2
        value = value.encode(ascii, backslashreplace)
    test_name = "{0}_{1}_{2}".format(name, index, value)
    return re.sub(r\W|^(?=\d), _, test_name)

 

重写后

    # Add zeros before index to keep order
    index = "{0:0{1}}".format(index + 1, index_len)
    if not is_trivial(value):
        if type(value) is dic and "api_name" in value.keys():
            value=value["api_name"]
        else:
            return "{0}_{1}".format(name, index)
    try:
        value = str(value)
    except UnicodeEncodeError:
        # fallback for python2
        value = value.encode(ascii, backslashreplace)
    test_name = "{0}_{1}_{2}".format(name, index, value)
    return re.sub(r\W|^(?=\d), _, test_name)

重写效果:

技术分享图片

 

python ddt 重写

原文:https://www.cnblogs.com/za0909/p/9129745.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!