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)

重写效果:

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