asp网站经常 响应,网站做支付宝支付需要哪些资料,图片优化软件,数字营销沙盘做接口测试#xff0c;使用unittestddtexcel ,使用HtmlTetstRunner来生成测试用例。 查看报告的时候 用例名称都是 test_api_1 、test_api_2 、test_api_3 的显示 #xff0c;看的不爽#xff0c;也不明确#xff0c;如果是test_api_登陆成功 、 test_api_密码错误 …做接口测试使用unittestddtexcel ,使用HtmlTetstRunner来生成测试用例。 查看报告的时候 用例名称都是 test_api_1 、test_api_2 、test_api_3 的显示 看的不爽也不明确如果是test_api_登陆成功 、 test_api_密码错误 这样是不是就很好去看这个报告了。不懂代码的也知道哪条通过哪条不通过可以对应去处理 而不是去excel数行数 分割线 查看了ddt源码代表用例名称的函数叫mk_test_name 源码啥样的就不讲了简单粗暴直接复制粘贴 ddt源码如下红色粗体部分标识 1 def mk_test_name(name, value, index0):2 3 Generate a new name for a test case.4 5 It will take the original test name and append an ordinal index and a6 string representation of the value, and convert the result into a valid7 python identifier by replacing extraneous characters with _.8 9 We avoid doing str(value) if dealing with non-trivial values.
10 The problem is possible different names with different runs, e.g.
11 different order of dictionary keys (see PYTHONHASHSEED) or dealing
12 with mock objects.
13 Trivial scalar values are passed as is.
14
15 A trivial value is a plain scalar, or a tuple or list consisting
16 only of trivial values.
17
18
19 # Add zeros before index to keep order
20 index {0:0{1}}.format(index 1, index_len)
21 if not is_trivial(value):
22 return {0}_{1}.format(name, index)
23 try:
24 value str(value)
25 except UnicodeEncodeError:
26 # fallback for python2
27 value value.encode(ascii, backslashreplace)
28 test_name {0}_{1}_{2}.format(name, index, value)
29 return re.sub(r\W|^(?\d), _, test_name) s上面是我的用例模板 想显示哪个就填哪个看下用例应该懂了吧不懂的加群问 2、修改ddt源码显示测试用例名字 如果传入数据为元组或字典。把下列代码替换源码红色区 if not is_trivial(value) and type(value) is not dict: return {0}_{1}_{2}.format(name, index,value.title)if type(value) is dict: try: value value[title] except: return {0}_{1}.format(name.index) 修改完成之后再次运行接口测试就可以在测试报告当中看到对应的用例名字啦。。 转载于:https://www.cnblogs.com/beile/p/10756827.html