def Run(startIndex, endIndex): a = ReadAndWriteFiles() path = a.pathcasesource # x1 = xlrd.open_workbook(path) # test_dir = a.path_casedir() test_report = a.path_testreport() # globalB.CsheetRows = x1.sheet_by_name("control").nrows datalist = a.read_case() globalB.CsheetRows = len(datalist) now = time.strftime("%Y-%m-%d_%H_%M_%S") filename = test_report + '\\' + 'result.html' # filename = test_report + '\\' + now + 'result.html' globalB.Gdriver = filename fp = open(filename, 'wb') runner = HTMLTestRunner(stream=fp, title='测试报告', description='用例执行情况:') testunit = unittest.TestSuite() loader = unittest.defaultTestLoader # for i in range(test_11.IndexSet.aIndex, globalB.CsheetRows): # for i in range( test_11.IndexSet.aIndex, 10 ): test_11.IndexSet.set(startIndex) for i in range(startIndex, endIndex): new_cls = type("用例" + str(i + 1), (test_11.Request1, ), {}) new_cls.__doc__ = datalist[i]['用例描述'] test_cases = loader.loadTestsFromTestCase(new_cls) if (test_cases != None): testunit.addTests(test_cases) runner.run(testunit) fp.close()
def func(): # 如果需要循环调用,就要添加以下方法 delePG = deleteOperate() deleHb = deleteHbase() a1 = generatecase.Run() time.sleep(5) # 替换服务器html,json a = ReadAndWriteFiles() shutil.copy( os.path.join(a.path_testreport(), "result" + ".json"), os.path.join(globalB.Gdjango_static_path, "report" + ".json")) path = shutil.copy( os.path.join(a.path_testreport(), "result" + ".html"), os.path.join(globalB.Gdjango_templates_path, "report" + ".html")) # 替换服务器脚本 new_str = '{% load static %}<script type="text/javascript" src="{% static "report.json" %}" charset="gbk"></script>' old_str = '<script type="text/javascript" src="result.json" charset="gbk"></script>' alter_text(path, old_str, new_str) # 截图 b = reportscreenshot() # 发邮件 EmailSend.sendmail(globalB.Gpng) # 获取现在时间 now_time = datetime.datetime.now() # 获取明天时间 next_time = now_time + datetime.timedelta(days=+1) next_year = next_time.date().year next_month = next_time.date().month next_day = next_time.date().day # 获取明天3点时间 next_time = datetime.datetime.strptime( str(next_year) + "-" + str(next_month) + "-" + str(next_day) + " 08:00:00", "%Y-%m-%d %H:%M:%S") # 获取距离明天3点时间,单位为秒 timer_start_time = (next_time - now_time).total_seconds() print(timer_start_time) timer = threading.Timer(timer_start_time, TimerLM.func) timer.start()
def func(): # 如果需要循环调用,就要添加以下方法 # deleHb = deleteHbase() # delePG = deleteOperate() a1 = generatecase.Run(0, 2) # a1 = generatecase.Run(0, 150) # 替换服务器html,json a = ReadAndWriteFiles() shutil.copy( os.path.join(a.path_testreport(), "result" + ".json"), os.path.join(globalB.Gdjango_static_path, "report" + ".json")) path = shutil.copy( os.path.join(a.path_testreport(), "result" + ".html"), os.path.join(globalB.Gdjango_templates_path, "report" + ".html")) # 替换服务器脚本 new_str = '{% load static %}<script type="text/javascript" src="{% static "report.json" %}" charset="gbk"></script>' old_str = '<script type="text/javascript" src="result.json" charset="gbk"></script>' alter_text(path, old_str, new_str) # 截图 b = reportscreenshot() # 发邮件 EmailSend.sendmail(globalB.Gpng)