Пример #1
0
    def test_ensure_cli_args(self):
        args1 = [
            "examples/postman_echo/request_methods/hardcode.yml", "--failfast"
        ]
        self.assertEqual(
            compat.ensure_cli_args(args1),
            ["examples/postman_echo/request_methods/hardcode.yml"],
        )

        args2 = [
            "examples/postman_echo/request_methods/hardcode.yml",
            "--save-tests"
        ]
        self.assertEqual(
            compat.ensure_cli_args(args2),
            ["examples/postman_echo/request_methods/hardcode.yml"],
        )
        self.assertTrue(os.path.isfile("examples/postman_echo/conftest.py"))

        args3 = [
            "examples/postman_echo/request_methods/hardcode.yml",
            "--report-file",
            "report.html",
        ]
        self.assertEqual(
            compat.ensure_cli_args(args3),
            [
                "examples/postman_echo/request_methods/hardcode.yml",
                "--html",
                "report.html",
                "--self-contained-html",
            ],
        )

        args4 = [
            "examples/postman_echo/request_methods/hardcode.yml",
            "--failfast",
            "--save-tests",
            "--report-file",
            "report.html",
        ]
        self.assertEqual(
            compat.ensure_cli_args(args4),
            [
                "examples/postman_echo/request_methods/hardcode.yml",
                "--html",
                "report.html",
                "--self-contained-html",
            ],
        )
Пример #2
0
def main_run(extra_args):
    # keep compatibility with v2
    extra_args = ensure_cli_args(extra_args)

    tests_path_list = []
    extra_args_new = []
    for item in extra_args:
        if not os.path.exists(item):
            # item is not file/folder path
            extra_args_new.append(item)
        else:
            # item is file/folder path
            tests_path_list.append(item)

    if len(tests_path_list) == 0:
        # has not specified any testcase path
        logger.error(f"No valid testcase path in cli arguments: {extra_args}")
        sys.exit(1)

    testcase_path_list = main_make(tests_path_list)
    if not testcase_path_list:
        logger.error("No valid testcases found, exit 1.")
        sys.exit(1)

    extra_args_new.extend(testcase_path_list)
    pytest.main(extra_args_new)
Пример #3
0
def main_run(extra_args) -> enum.IntEnum:
    capture_message("start to run")
    # keep compatibility with v2
    extra_args = ensure_cli_args(extra_args)

    tests_path_list = []
    extra_args_new = []
    for item in extra_args:
        if not os.path.exists(item):
            # item is not file/folder path
            extra_args_new.append(item)
        else:
            # item is file/folder path
            tests_path_list.append(item)

    if len(tests_path_list) == 0:
        # has not specified any testcase path
        logger.error(f"No valid testcase path in cli arguments: {extra_args}")
        sys.exit(1)

    testcase_path_list = main_make(tests_path_list)
    if not testcase_path_list:
        logger.error("No valid testcases found, exit 1.")
        sys.exit(1)

    if "--tb=short" not in extra_args_new:
        extra_args_new.append("--tb=short")

    extra_args_new.extend(testcase_path_list)
    return pytest.main(extra_args_new)
Пример #4
0
def main_run(extra_args) -> enum.IntEnum:
    ga_client.track_event("RunAPITests", "hrun")
    # keep compatibility with v2
    extra_args = ensure_cli_args(extra_args)

    tests_path_list = []
    extra_args_new = []
    for item in extra_args:
        if not os.path.exists(item):
            # item is not file/folder path
            extra_args_new.append(item)
        else:
            # item is file/folder path
            tests_path_list.append(item)

    if len(tests_path_list) == 0:
        # has not specified any testcase path
        logger.error(f"No valid testcase path in cli arguments: {extra_args}")
        sys.exit(1)

    testcase_path_list = main_make(tests_path_list)
    if not testcase_path_list:
        logger.error("No valid testcases found, exit 1.")
        sys.exit(1)

    if "--tb=short" not in extra_args_new:
        extra_args_new.append("--tb=short")

    extra_args_new.extend(testcase_path_list)
    logger.info(f"start to run tests with pytest. HttpRunner version: {__version__}")
    return pytest.main(extra_args_new)
Пример #5
0
def main_run(extra_args, config) -> enum.IntEnum:
    capture_message("start to run")
    logger.debug(f"[main run] config ==> {config}")
    logger.debug(f"[main run] extra_args ==> {extra_args}")
    # keep compatibility with v2
    extra_args = ensure_cli_args(extra_args)

    tests_path_list = []
    extra_args_new = []
    for item in extra_args:
        if not os.path.exists(item):
            # item is not file/folder path
            extra_args_new.append(item)
        else:
            # item is file/folder path
            tests_path_list.append(item)

    if config:
        extra_args_new.append(f"--config={config}")

    if len(tests_path_list) == 0:
        # has not specified any test_cases path
        logger.error(f"No valid testcase path in cli arguments: {extra_args}")
        sys.exit(1)

    testcase_path_list = main_make(tests_path_list)
    # config_to_debugtalk_make(config)
    # move_pytest_files_to_target(os.path.join(BASE_DIR, "test_cases"))
    # if not testcase_path_list:
    #     logger.error("No valid testcases found, exit 1.")
    #     sys.exit(1)

    if "--tb=short" not in extra_args_new:
        extra_args_new.append("--tb=short")
    if "-v" not in extra_args_new:
        extra_args_new.append("-v")
    for index, testcase_path in enumerate(testcase_path_list):
        testcase_path_list[index] = testcase_path.replace("test_cases", "target")
    extra_args_new.extend(testcase_path_list)
    logger.info(f"start to run tests with pytest. HttpRunner version: {__version__}")
    logger.info(f"extra_args_new ==> {extra_args_new}")
    return pytest.main(extra_args_new)