Example #1
0
def suite_hrun(name, base_url, suite, receiver):
    """
    异步运行模块
    :param env_name: str: 环境地址
    :param project: str:项目所属模块
    :param module: str:模块名称
    :return:
    """
    logger.info("异步运行套件")

    suite = list(suite)

    testcase_dir_path = os.path.join(
        os.path.dirname(os.path.split(os.path.realpath(__file__))[0]), "suite")
    testcase_dir_path = os.path.join(testcase_dir_path, get_time_stamp())

    try:
        for value in suite:
            run_by_suite(value[0], base_url, testcase_dir_path)
    except ObjectDoesNotExist:
        return '找不到Suite信息'

    summary = main_run_cases(testcase_dir_path)
    report_path = add_test_reports(summary, report_name=name)

    if receiver != '':
        send_email_reports(receiver, report_path)
    os.remove(report_path)
Example #2
0
def suite_hrun(name, base_url, suite, receiver):
    """
    异步运行模块
    :param env_name: str: 环境地址
    :param project: str:项目所属模块
    :param module: str:模块名称
    :return:
    """
    logger.setup_logger('INFO')
    kwargs = {
        "failfast": False,
    }
    runner = HttpRunner(**kwargs)
    suite = list(suite)

    testcase_dir_path = os.path.join(os.getcwd(), "suite")
    testcase_dir_path = os.path.join(testcase_dir_path, get_time_stamp())

    try:
        for value in suite:
            run_by_suite(value[0], base_url, testcase_dir_path)
    except ObjectDoesNotExist:
        return '找不到Suite信息'


    runner.run(testcase_dir_path)

    shutil.rmtree(testcase_dir_path)
    runner.summary = timestamp_to_datetime(runner.summary)
    add_test_reports(report_name=name, **runner.summary)

    if receiver != '':
        send_html_reports(receiver, runner)

    return runner.summary
Example #3
0
def suite_hrun(name, base_url, suite, receiver):
    """
    异步运行模块
    :param env_name: str: 环境地址
    :param project: str:项目所属模块
    :param module: str:模块名称
    :return:
    """
    logger.setup_logger('INFO')
    kwargs = {
        "failfast": False,
    }
    runner = HttpRunner(**kwargs)
    suite = list(suite)

    testcase_dir_path = os.path.join(os.getcwd(), "suite")
    testcase_dir_path = os.path.join(testcase_dir_path, get_time_stamp())

    try:
        for value in suite:
            run_by_suite(value[0], base_url, testcase_dir_path)
    except ObjectDoesNotExist:
        return '找不到Suite信息'

    # runner.run(testcase_dir_path)
    runner.summary = runner.run(testcase_dir_path)
    shutil.rmtree(testcase_dir_path)

    runner.summary = timestamp_to_datetime(runner.summary)

    # report_path = add_test_reports(runner, report_name=name)
    report_result = add_test_reports(runner, report_name=name)
    report_path, report_id = report_result[0], report_result[1]

    # 处理报告结果失败,发送失败主题邮件
    if not runner.summary.get('success', None):
        FailName = []
        for i in runner.summary.get('details'):
            if i.get('success') == False:
                FailName.append(i.get('name'))
        # subjects = "定时任务出现错误情况预警通知"
        status = "【 失败 】"
        bodyText = "{}定时任务执行失败用例如下:<br>&emsp; {} <br> 请套件相关维护人员及时确认!!!".format(
            name, '<br> &emsp;'.join(FailName))
        send_email_reports(receiver,
                           report_path,
                           name=name,
                           bodyText=bodyText,
                           status=status)
        os.remove(report_path)
        # 调用dingding机器人发送失败通知
        bodyText = "{}定时任务执行失败用例如下:\n {}\n如需了解更多内容,请关注邮箱中邮件!".format(
            name, '\n '.join(FailName))
        callDingTalkRobot(name, bodyText)
        return ""

    # 处理接口响应时长超时,发送告警邮件
    timeOut_result = statistics_summary_timeOut(runner.summary)
    if timeOut_result:
        status = "【 告警 】"
        bodyText = "{0}定时任务执行接口时长告警用例如下: {1}".format(
            name, write_htmlTable(timeOut_result))
        # 创建bug
        createrZentaoBug(suite[0], timeOut_result, report_id=report_id)
        send_email_reports(receiver,
                           report_path,
                           name=name,
                           bodyText=bodyText,
                           status=status)
    if receiver != '':
        send_email_reports(receiver, report_path, name=name)
    os.remove(report_path)