コード例 #1
0
def runCase(caseSuites):
    if isinstance(caseSuites, list):
        [__import__(str) for str in caseSuites]
        testSuite = unittest.TestSuite()
        suites = [
            unittest.TestLoader().loadTestsFromName(str) for str in caseSuites
        ]
        [testSuite.addTest(suite) for suite in suites]
        report_file = os.path.join(os.getcwd() + "\\tr\\tmp\\%s.html" %
                                   time.strftime("%Y_%m_%d_%H_%M_%S"))
        fp = file(report_file, 'wb')
        runner = HTMLTestRunner(stream=fp,
                                title=u'测试报告',
                                description=u'一路乐旅游自动化测试报告详细信息')
        result = runner.run(testSuite)
        fp.close()
        if result:
            index_file = os.path.join(os.getcwd() + "\\tr\\index.html")
            shutil.copy(report_file, index_file)
        allError = result.errors
        errorCase = [error[0].id() for error in allError]
        strError = ','.join(errorCase)
        AllFailures = result.failures
        failuresCase = [failures[0].id() for failures in AllFailures]
        strFailures = ','.join(failuresCase)
        errorCount = result.error_count
        rightCount = result.success_count
        failuresCount = result.failure_count
        caseCount = len(result.result)
        startTime = runner.startTime
        stopTime = runner.stopTime
        runTime = stopTime - startTime
        sql_count = "insert into run_result_count " \
            "values(null,'%s',%d,%d,%d,%d,'%s','%s','%s','%s',datetime('now', '+8 hour'))"\
            % (runTime,
               caseCount,
               errorCount,
               rightCount,
               failuresCount,
               strError,
               strFailures,
               startTime,
               stopTime)
        rid = reportDB().insertSql(sql_count)
        for resultOne in result.result:
            caseList = resultOne[1].id().split('.')
            caseClass = '.'.join(caseList[-2:])
            caseName = caseList[-1]
            caseStatus = resultOne[0]
            caseErrorInfo = resultOne[-1].replace("'", '"')
            sql_detail =  "insert into case_run_detail " \
                          "values(null,'%s','%s',%d,'%s',%d,datetime('now','+8 hour'))"\
                          % (caseName,
                             caseClass,
                             caseStatus,
                             caseErrorInfo,
                             rid)
            reportDB().insertSql(sql_detail)
    else:
        raise (TypeError, u'arg is must list')
コード例 #2
0
def runCase(caseSuites):
    if isinstance(caseSuites, list):
        [__import__(str) for str in caseSuites]
        testSuite = unittest.TestSuite()
        suites = [unittest.TestLoader().loadTestsFromName(str)
                  for str in caseSuites]
        [testSuite.addTest(suite) for suite in suites]
        report_file = os.path.join(
            os.getcwd() + "\\tr\\tmp\\%s.html" % time.strftime("%Y_%m_%d_%H_%M_%S"))
        fp = file(report_file, 'wb')
        runner = HTMLTestRunner(
            stream=fp, title=u'测试报告', description=u'一路乐旅游自动化测试报告详细信息')
        result = runner.run(testSuite)
        fp.close()
        if result:
            index_file = os.path.join(os.getcwd() + "\\tr\\index.html")
            shutil.copy(report_file, index_file)
        allError = result.errors
        errorCase = [error[0].id() for error in allError]
        strError = ','.join(errorCase)
        AllFailures = result.failures
        failuresCase = [failures[0].id() for failures in AllFailures]
        strFailures = ','.join(failuresCase)
        errorCount = result.error_count
        rightCount = result.success_count
        failuresCount = result.failure_count
        caseCount = len(result.result)
        startTime = runner.startTime
        stopTime = runner.stopTime
        runTime = stopTime - startTime
        sql_count = "insert into run_result_count " \
            "values(null,'%s',%d,%d,%d,%d,'%s','%s','%s','%s',datetime('now', '+8 hour'))"\
            % (runTime,
               caseCount,
               errorCount,
               rightCount,
               failuresCount,
               strError,
               strFailures,
               startTime,
               stopTime)
        rid = reportDB().insertSql(sql_count)
        for resultOne in result.result:
            caseList = resultOne[1].id().split('.')
            caseClass = '.'.join(caseList[-2:])
            caseName = caseList[-1]
            caseStatus = resultOne[0]
            caseErrorInfo = resultOne[-1].replace("'", '"')
            sql_detail =  "insert into case_run_detail " \
                          "values(null,'%s','%s',%d,'%s',%d,datetime('now','+8 hour'))"\
                          % (caseName,
                             caseClass,
                             caseStatus,
                             caseErrorInfo,
                             rid)
            reportDB().insertSql(sql_detail)
    else:
        raise(TypeError, u'arg is must list')
コード例 #3
0
 def bargraph(self):
     ind = np.arange(int(self.count))
     width = 0.25
     data = reportDB().selectSql(self.LATE_FIVE_SQL)
     errorsList = tuple(error[0] for error in data)[::-1]
     passedList = tuple(right[1] for right in data)[::-1]
     failedList = tuple(fail[2] for fail in data)[::-1]
     startTime = tuple(runtime[3] for runtime in data)[::-1]
     fig, ax = plt.subplots()
     ax.set_ylabel(u'个数')
     ax.set_title(u'最近%s次测试结果柱状图' % self.count)
     ax.set_xticks(ind+width)
     ax.set_xticklabels(startTime,rotation=18, fontsize='small')
     rectError = ax.bar(ind, errorsList, width, color='r')
     rectFail = ax.bar(ind+width, failedList, width, color='y')
     rectPass = ax.bar(ind+2*width, passedList, width, color='g')
     fontP = FontProperties()
     fontP.set_size('small')
     for e_rect in rectError:
         height = e_rect.get_height()
         ax.text(e_rect.get_x()+e_rect.get_width()/2., 1.05*height, '%d'%int(height),
                 ha='center', va='bottom')
     for f_rect in rectFail:
         height = f_rect.get_height()
         ax.text(f_rect.get_x()+f_rect.get_width()/2., 1.05*height, '%d'%int(height),
                 ha='center', va='bottom')
     for p_rect in rectPass:
         height = p_rect.get_height()
         ax.text(p_rect.get_x()+p_rect.get_width()/2., 0.8*height, '%d'%int(height),
                 ha='center', va='bottom')
     ax.legend( (rectError[0], rectPass[0], rectFail[0]), (u'错误', u'通过', u'失败'),prop = fontP)
     plt.savefig('E:\\apk\huodong\\tr\\pic\\bargraph')
コード例 #4
0
 def linegraph(self):
     data = reportDB().selectSql(self.ALL_PASS_FAILED)
     errors = tuple(error[0] for error in data)
     rights = tuple(right[1] for right in data)
     plt.ylabel(u'个数')
     plt.title(u'测试结果线性图')
     plt.plot(errors,color='r')
     plt.plot(rights, color='g')
     plt.savefig('E:\\apk\huodong\\tr\\pic\\linegraph')
コード例 #5
0
 def linegraph(self):
     data = reportDB().selectSql(self.ALL_PASS_FAILED)
     errors = tuple(error[0] for error in data)
     rights = tuple(right[1] for right in data)
     plt.ylabel(u'个数')
     plt.title(u'测试结果线性图')
     plt.plot(errors, color='r')
     plt.plot(rights, color='g')
     plt.savefig('E:\\apk\huodong\\tr\\pic\\linegraph')
コード例 #6
0
 def bargraph(self):
     ind = np.arange(int(self.count))
     width = 0.25
     data = reportDB().selectSql(self.LATE_FIVE_SQL)
     errorsList = tuple(error[0] for error in data)[::-1]
     passedList = tuple(right[1] for right in data)[::-1]
     failedList = tuple(fail[2] for fail in data)[::-1]
     startTime = tuple(runtime[3] for runtime in data)[::-1]
     fig, ax = plt.subplots()
     ax.set_ylabel(u'个数')
     ax.set_title(u'最近%s次测试结果柱状图' % self.count)
     ax.set_xticks(ind + width)
     ax.set_xticklabels(startTime, rotation=18, fontsize='small')
     rectError = ax.bar(ind, errorsList, width, color='r')
     rectFail = ax.bar(ind + width, failedList, width, color='y')
     rectPass = ax.bar(ind + 2 * width, passedList, width, color='g')
     fontP = FontProperties()
     fontP.set_size('small')
     for e_rect in rectError:
         height = e_rect.get_height()
         ax.text(e_rect.get_x() + e_rect.get_width() / 2.,
                 1.05 * height,
                 '%d' % int(height),
                 ha='center',
                 va='bottom')
     for f_rect in rectFail:
         height = f_rect.get_height()
         ax.text(f_rect.get_x() + f_rect.get_width() / 2.,
                 1.05 * height,
                 '%d' % int(height),
                 ha='center',
                 va='bottom')
     for p_rect in rectPass:
         height = p_rect.get_height()
         ax.text(p_rect.get_x() + p_rect.get_width() / 2.,
                 0.8 * height,
                 '%d' % int(height),
                 ha='center',
                 va='bottom')
     ax.legend((rectError[0], rectPass[0], rectFail[0]),
               (u'错误', u'通过', u'失败'),
               prop=fontP)
     plt.savefig('E:\\apk\huodong\\tr\\pic\\bargraph')