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.

case.py 3.5 KiB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2017/6/4 20:15
  3. # @Author : lileilei
  4. # @File : case.py
  5. from Interface.testFengzhuang import TestApi
  6. from Public.get_excel import datacel
  7. from Public.log import LOG, logger
  8. import os
  9. from config.config import Config_Try_Num, TestPlanUrl
  10. path = os.path.join(os.path.join(os.getcwd(), 'test_case_data'), 'case.xlsx')
  11. listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel(path)
  12. from Public.panduan import assert_in
  13. @logger('测试')
  14. def testinterface():
  15. list_pass = 0
  16. list_fail = 0
  17. list_json = []
  18. listrelust = []
  19. list_weizhi = 0
  20. list_exption = 0
  21. error_num = 0
  22. for i in range(len(listurl)):
  23. while error_num <= Config_Try_Num + 1:
  24. parem = {'key': listkey[i]}
  25. parem.update({'info': eval(listconeent[i])})
  26. #parem=eval(data_test[listconeent[i])
  27. api = TestApi(url=TestPlanUrl + listurl[i], parame=parem, method=listfangshi[i])
  28. apijson = api.getJson()
  29. if apijson['code'] == 0:
  30. LOG.info('inputdata> 参数:%s, url:%s ,返回:%s,预期:%s' % (listconeent[i], listurl[i], apijson, listqiwang[i]))
  31. assert_re = assert_in(asserassert=listqiwang[i], returnjson=apijson)
  32. if assert_re['code'] == 0:
  33. list_json.append(apijson['result'])
  34. listrelust.append('pass')
  35. list_pass += 1
  36. error_num = 0
  37. continue
  38. elif assert_re['code'] == 1:
  39. if error_num <= Config_Try_Num:
  40. error_num += 1
  41. LOG.info('失败重试中')
  42. else:
  43. LOG.info('失败重试中次数用完,最后结果')
  44. error_num = 0
  45. list_fail += 1
  46. listrelust.append('fail')
  47. list_json.append(apijson['result'])
  48. break
  49. elif assert_re['code'] == 2:
  50. if error_num < Config_Try_Num:
  51. error_num += 1
  52. LOG.info('失败重试中')
  53. else:
  54. LOG.info('失败重试中次数用完,最后结果')
  55. error_num = 0
  56. list_exption += 1
  57. listrelust.append('exception')
  58. list_json.append(assert_re['result'])
  59. break
  60. else:
  61. if error_num < Config_Try_Num:
  62. error_num += 1
  63. LOG.info('失败重试中')
  64. else:
  65. LOG.info('失败重试中次数用完,最后结果')
  66. error_num = 0
  67. list_weizhi += 1
  68. listrelust.append('未知错误')
  69. list_json.append('未知错误')
  70. break
  71. else:
  72. if error_num < Config_Try_Num:
  73. error_num += 1
  74. LOG.info('失败重试中')
  75. else:
  76. LOG.info('失败重试中次数用完,最后结果')
  77. error_num = 0
  78. list_exption += 1
  79. listrelust.append('exception')
  80. list_json.append(apijson['result'])
  81. break
  82. return listrelust, list_fail, list_pass, list_json, list_exption, list_weizhi

Introduction

生成接口测试报告

No topics