Beispiel #1
0
def run_testcase(instance, testcase_dir_path):
    """
    运行用例
    :return:
    :param instance: 实例
    :param testcase_dir_path: 用例根目录路径
    :return dict
    """
    runner = HttpRunner()
    # runner.run(testcase_dir_path)
    try:
        runner.run(testcase_dir_path)
    except ParamsError:
        logger.error("用例参数有误")
        data = {"msg": "用例参数有误"}
        return Response(data, status=400)

    runner.summary = timestamp_to_datetime(runner.summary, type=False)

    try:
        report_name = instance.name
    except Exception as e:
        report_name = '被遗弃的报告' + '-' + datetime.strftime(
            datetime.now(), '%Y%m%d%H%M%S')

    report_id = create_report(runner, report_name=report_name)
    data_dict = {"id": report_id}

    return Response(data_dict, status=status.HTTP_201_CREATED)
Beispiel #2
0
def run_testcase(instance, testcase_dir_path):
    # 1、创建HttpRunner对象
    runner = HttpRunner()
    try:
        # 2、运行用例
        runner.run(testcase_dir_path)
    except Exception as e:
        res = {'msg': '用例执行失败', 'code': '0'}
        return Response(res, status=400)

    # 3、创建报告
    report_id = generate_report(runner, instance)
    return Response({'id': report_id}, status=201)
Beispiel #3
0
def run_testcase(instance, testcase_dir_path):
    runner = HttpRunner()
    runner.run(testcase_dir_path)

    runner.summary = timestamp_to_datetime(runner.summary, type=False)
    try:
        report_name = instance.name
    except Exception as e:
        report_name = '遗弃的报告' + '-' + datetime.strftime(datetime.now())
    report_id = create_report(runner, report_name=report_name)
    data_dict = {"id": report_id}

    return Response(data_dict, status=status.HTTP_201_CREATED)
Beispiel #4
0
def run_testcase(instance, testcase_dir_path):
    # 1、运行用例
    runner = HttpRunner()
    try:
        runner.run(testcase_dir_path)
    except:
        res = {'ret': False, 'msg': '用例执行失败'}
        return Response(res, status=400)

    # 2、创建报告
    report_id = create_report(runner, instance.name)

    # 3、用例运行成功之后,需要把生成的报告id返回
    data = {'id': report_id}
    return Response(data, status=201)
Beispiel #5
0
def run_testcase(instance, testcase_dir_path):
    runner = HttpRunner()
    runner.run(testcase_dir_path)
    # runner.summary 统计了用例运行详情
    runner.summary = timestamp_to_datetime(runner.summary, type=False)

    try:
        # 报告名称为用例名称
        report_name = instance.name
    except Exception as e:  # 如果报告名称不存在:
        report_name = '被遗弃的报告' + '-' + datetime.strftime(
            datetime.now(), '%Y%m%d%H%M%S%f')
    # create_report生成报告,返回报告id值
    report_id = create_report(runner, report_name=report_name)
    data_dict = {"id": report_id}

    return Response(data_dict, status=status.HTTP_201_CREATED)
Beispiel #6
0
def run_testcase(instance, testcase_dir_path):
    # 运行函数
    runner = HttpRunner()
    try:
        runner.run(testcase_dir_path)
    except Exception as e:
        res = {
            "ret": False,
            "msg": "用例执行失败",
            "log": e
        }
        return Response(res, status=400)
    # 生成报告获取报告id
    report_id = create_report(runner, instance.name)
    # 用例运行完毕后返回报告id
    data = {
        "id": report_id
    }
    return Response(data, status=201)
Beispiel #7
0
def run_testcase(instance, testcase_dir_path, is_email=False, email='', debug=False):
    """
    运行用例
    :return:
    :param instance: 实例
    :param testcase_dir_path: 用例根目录路径
    :return dict
    """
    runner = HttpRunner()
    # runner.run(testcase_dir_path)
    try:
        runner.run(testcase_dir_path)
    except ParamsError:
        logger.error("用例参数有误")
        data = {
            "msg": "用例参数有误"
        }
        return Response(data, status=400)

    runner.summary = timestamp_to_datetime(runner.summary, type=False)

    if debug:
        return runner.summary

    try:
        report_name = instance.name
    except Exception as e:
        report_name = '被遗弃的报告' + '-' + datetime.strftime(datetime.now(), '%Y%m%d%H%M%S')

    report = create_report(runner, report_name=report_name)
    data_dict = {
        "id": report.id
    }
    if is_email:
        report_full_path = report.html
        content = "执行结果:{},用例总数:{},成功总数:{},详情请查看测试报告。" \
            .format("Pass" if report.result == 1 else "Fail", report.count, report.success)
        send_email_text(report.name, content, report_full_path, email)

    return Response(data_dict, status=status.HTTP_200_OK)