ddt源码修改:HtmlTestRunner报告依据接口名显示用例名字
修改后的ddt源码为(红色粗体部分为修改的内容):
1 def mk_test_name(name, value, index=0): 2 3 print("-------first value------------") 4 print(value) 5 # Add zeros before index to keep order 6 index = "{0:0{1}}".format(index + 1, index_len) 7 #添加了对字典数据的处理。 8 if not is_trivial(value) and type(value) is not dict: 9 return "{0}_{1}".format(name, index) 10 #如果数据是字典,则获取字典当中的api_name对应的值,加到测试用例名称中。 11 if type(value) is dict: 12 try: 13 value = value["case_name"] #case_name作为value值 14 except: 15 return "{0}_{1}".format(name, index) 16 try: 17 value = str(value) 18 except UnicodeEncodeError: 19 # fallback for python2 20 value = value.encode('ascii', 'backslashreplace') 21 test_name = "{0}_{1}_{2}".format(name, index, value) 22 23 return re.sub(r'\W|^(?=\d)', '_', test_name)
此文章转自https://www.cnblogs.com/Simple-Small/p/9230382.html,具体详情可看这篇文章