python ddt 重写

对此方法重写

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)
复制代码

重写效果:

 

posted @   py_lea  阅读(332)  评论(3编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示