You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

pyreport_excel.py 4.5 KiB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # encoding: utf-8
  2. """
  3. @author: lileilei
  4. @file: pyreport_excel.py
  5. @time: 2017/6/7 8:47
  6. """
  7. import os, xlwt, yaml
  8. from xlwt import *
  9. def yangshi1():
  10. style = XFStyle()
  11. fnt = Font()
  12. fnt.name = u'微软雅黑'
  13. fnt.bold = True
  14. style.font = fnt
  15. alignment = xlwt.Alignment()
  16. alignment.horz = xlwt.Alignment.HORZ_CENTER
  17. alignment.vert = xlwt.Alignment.VERT_CENTER
  18. style.alignment = alignment # 给样式添加文字居中属性
  19. style.font.height = 430 # 设置字体大小
  20. return style
  21. def yangshi2():
  22. style1 = XFStyle()
  23. alignment = xlwt.Alignment()
  24. alignment.horz = xlwt.Alignment.HORZ_CENTER
  25. alignment.vert = xlwt.Alignment.VERT_CENTER
  26. style1.alignment = alignment # 给样式添加文字居中属性
  27. style1.font.height = 330 # 设置字体大小
  28. return style1
  29. def yangshi3():
  30. style1 = XFStyle()
  31. style1.font.height = 330 # 设置字体大小
  32. return style1
  33. def yangshique(me):
  34. if me == 'pass':
  35. style = yangshi1()
  36. Pattern = xlwt.Pattern()
  37. Pattern.pattern = xlwt.Pattern.SOLID_PATTERN
  38. Pattern.pattern_fore_colour = xlwt.Style.colour_map['green']
  39. style.pattern = Pattern
  40. else:
  41. style = yangshi2()
  42. Pattern = xlwt.Pattern()
  43. Pattern.pattern = xlwt.Pattern.SOLID_PATTERN
  44. Pattern.pattern_fore_colour = xlwt.Style.colour_map['red']
  45. style.pattern = Pattern
  46. return style
  47. def create(filename, list_pass, list_fail, listids, listnames, listkeys, listconeents, listurls, listfangshis,
  48. listqiwangs, list_json, listrelust):
  49. filepath = open(os.path.join(os.path.join(os.getcwd(), 'config'), 'test_report.yaml'), encoding='utf-8')
  50. file_config = yaml.load(filepath, Loader=yaml.FullLoader)
  51. file = Workbook(filename)
  52. table = file.add_sheet('测试结果', cell_overwrite_ok=True)
  53. style = yangshi1()
  54. for i in range(0, 7):
  55. table.col(i).width = 380 * 20
  56. style1 = yangshi2()
  57. table.write_merge(0, 0, 0, 6, '测试报告', style=style)
  58. table.write_merge(1, 1, 0, 6, '', style=style)
  59. table.write_merge(2, 3, 0, 6, '测试详情', style=style1)
  60. table.write(4, 0, '项目名称', style=style1)
  61. table.write(5, 0, '接口版本', style=style1)
  62. table.write(6, 0, '提测时间', style=style1)
  63. table.write(7, 0, '提测人', style=style1)
  64. table.write(4, 2, '测试人', style=style1)
  65. table.write(5, 2, '测试时间', style=style1)
  66. table.write(6, 2, '审核人', style=style1)
  67. table.write(4, 4, '通过', style=style1)
  68. table.write(5, 4, '失败', style=style1)
  69. table.write(6, 4, '成功率', style=style1)
  70. table.write(4, 1, (file_config['projectname']), style=style1)
  71. table.write(5, 1, file_config['interfaceVersion'], style=style1)
  72. table.write(6, 1, file_config['tijiao_time'], style=style1)
  73. table.write(7, 1, file_config['tijiao_person'], style=style1)
  74. table.write(4, 3, file_config['ceshi_person'], style=style1)
  75. table.write(5, 3, file_config['ceshi_time'], style=style1)
  76. table.write(6, 3, file_config['shenhename'], style=style1)
  77. table.write(4, 5, (list_pass), style=style1)
  78. table.write(5, 5, (list_fail), style=style1)
  79. table.write(6, 5, ('%.2f%%' % ((list_pass) / (len(listrelust)))), style=style1)
  80. table1 = file.add_sheet('测试详情', cell_overwrite_ok=True)
  81. table1.write_merge(0, 0, 0, 8, '测试详情', style=style)
  82. for i in range(0, 8):
  83. table1.col(i).width = 400 * 20
  84. table1.write(1, 0, '用例ID', style=yangshi3())
  85. table1.write(1, 1, '用例名字', style=yangshi3())
  86. table1.write(1, 2, 'key', style=yangshi3())
  87. table1.write(1, 3, '请求内容', style=yangshi3())
  88. table1.write(1, 4, ' url', style=yangshi3())
  89. table1.write(1, 5, '请求方式', style=yangshi3())
  90. table1.write(1, 6, '预期', style=yangshi3())
  91. table1.write(1, 7, '实际返回', style=yangshi3())
  92. table1.write(1, 8, '结果', style=yangshi3())
  93. for i in range(len(listids)):
  94. table1.write(i + 1, 0, listids[i], style=yangshi3())
  95. table1.write(i + 1, 1, listnames[i], style=yangshi3())
  96. table1.write(i + 1, 2, listkeys[i], style=yangshi3())
  97. table1.write(i + 1, 3, listconeents[i], style=yangshi3())
  98. table1.write(i + 1, 4, listurls[i], style=yangshi3())
  99. table1.write(i + 1, 5, listfangshis[i], style=yangshi3())
  100. table1.write(i + 1, 6, listqiwangs[i], style=yangshi3())
  101. table1.write(i + 1, 7, str(list_json[i]), style=yangshi3())
  102. table1.write(i + 1, 8, listrelust[i], style=yangshique(listrelust[i]))
  103. file.save(filename)

Introduction

生成接口测试报告

No topics

Contributors (2)