def _get_test_definition(name, ref_type): """ get expected api or testcase. Args: name (str): api or testcase name ref_type (enum): "def-api" or "def-testcase" Returns: dict: expected api/testcase info if found. Raises: exceptions.ApiNotFound: api not found exceptions.TestcaseNotFound: testcase not found """ block = project_mapping.get(ref_type, {}).get(name) if not block: err_msg = "{} not found!".format(name) if ref_type == "def-api": raise exceptions.ApiNotFound(err_msg) else: # ref_type == "def-testcase": raise exceptions.TestcaseNotFound(err_msg) return block
def __make(tests_path: Text, ref_flag: bool = False) -> NoReturn: """ make testcase(s) with testcase/testsuite/folder absolute path generated pytest file path will be cached in make_files_cache_set Args: tests_path: should be in absolute path ref_flag: flag if referenced test path """ test_files = [] if os.path.isdir(tests_path): files_list = load_folder_files(tests_path) test_files.extend(files_list) elif os.path.isfile(tests_path): test_files.append(tests_path) else: raise exceptions.TestcaseNotFound(f"Invalid tests path: {tests_path}") for test_file in test_files: if test_file.lower().endswith("_test.py"): pytest_files_set.add(test_file) continue try: test_content = load_test_file(test_file) except (exceptions.FileNotFound, exceptions.FileFormatError) as ex: logger.warning(ex) continue # api in v2 format, convert to v3 testcase if "request" in test_content: test_content = ensure_testcase_v3_api(test_content) test_content.setdefault("config", {})["path"] = test_file # testcase if "teststeps" in test_content: try: make_testcase(test_content, ref_flag=ref_flag) except exceptions.TestCaseFormatError: continue # testsuite elif "testcases" in test_content: try: make_testsuite(test_content) except exceptions.TestSuiteFormatError: continue # invalid format else: logger.warning( f"skip invalid testcase/testsuite file: {test_file}")
def __make(tests_path: Text) -> NoReturn: """ make testcase(s) with testcase/testsuite/folder absolute path generated pytest file path will be cached in make_files_cache_set Args: tests_path: should be in absolute path """ test_files = [] if os.path.isdir(tests_path): files_list = load_folder_files(tests_path) test_files.extend(files_list) elif os.path.isfile(tests_path): test_files.append(tests_path) else: raise exceptions.TestcaseNotFound(f"Invalid tests path: {tests_path}") for test_file in test_files: try: test_content = load_test_file(test_file) except (exceptions.FileNotFound, exceptions.FileFormatError) as ex: logger.warning(ex) continue # api in v2 format, convert to v3 testcase if "request" in test_content: test_content = ensure_testcase_v3_api(test_content) test_content.setdefault("config", {})["path"] = test_file # testcase if "teststeps" in test_content: try: __make_testcase(test_content) except exceptions.TestCaseFormatError: continue # testsuite elif "testcases" in test_content: try: __make_testsuite(test_content) except exceptions.TestSuiteFormatError: continue # invalid format else: raise exceptions.FileFormatError( f"test file is neither testcase nor testsuite: {test_file}")
def __make(tests_path: Text) -> List: test_files = [] if os.path.isdir(tests_path): files_list = load_folder_files(tests_path) test_files.extend(files_list) elif os.path.isfile(tests_path): test_files.append(tests_path) else: raise exceptions.TestcaseNotFound(f"Invalid tests path: {tests_path}") testcase_path_list = [] for test_file in test_files: try: test_content = load_test_file(test_file) test_content.setdefault("config", {})["path"] = test_file except (exceptions.FileNotFound, exceptions.FileFormatError) as ex: logger.warning(ex) continue # testcase if "teststeps" in test_content: try: testcase_file = make_testcase(test_content) except exceptions.TestCaseFormatError: continue testcase_path_list.append(testcase_file) # testsuite elif "testcases" in test_content: try: testcase_files = make_testsuite(test_content) except exceptions.TestSuiteFormatError: continue testcase_path_list.extend(testcase_files) # invalid format else: raise exceptions.FileFormatError( f"test file is neither testcase nor testsuite: {test_file}" ) if not testcase_path_list: logger.warning(f"No valid testcase generated on {tests_path}") return [] return testcase_path_list
def _get_test_definition(name, ref_type): """ get expected api or testcase. @params: name: api or testcase name ref_type: "api" or "suite" @return expected api info if found, otherwise raise ApiNotFound exception """ block = overall_def_dict.get(ref_type, {}).get(name) if not block: err_msg = "{} not found!".format(name) if ref_type == "api": raise exceptions.ApiNotFound(err_msg) else: # ref_type == "suite": raise exceptions.TestcaseNotFound(err_msg) return block
def make(tests_path: Text) -> List: testcases = [] if os.path.isdir(tests_path): files_list = load_folder_files(tests_path) testcases.extend(files_list) elif os.path.isfile(tests_path): testcases.append(tests_path) else: raise exceptions.TestcaseNotFound(f"Invalid tests path: {tests_path}") testcase_path_list = [] for testcase_path in testcases: testcase_path = make_testcase(testcase_path) if not testcase_path: continue testcase_path_list.append(testcase_path) format_with_black(tests_path) return testcase_path_list
def _get_test_definition(name, ref_type): ''' get expected api or testcase. Args: name (str): specified api or testcase name ref_type (enum): "def-api" or "testcase" Returns: dict: expected api/testcase info if found. Raises: exceptions.ApiNotFound: api not found exceptions.TestcaseNotFound: testcase not found ''' block = project_mapping.get(ref_type, {}).get(name) if not block: err_msg = f'{name} not found!' if ref_type == 'def-api': logger.log_error(err_msg) raise exceptions.ApiNotFound(err_msg) else: logger.log_error(err_msg) raise exceptions.TestcaseNotFound(err_msg) return block
def __make(tests_path: Text) -> NoReturn: """ make testcase(s) with testcase/testsuite/folder absolute path generated pytest file path will be cached in pytest_files_made_cache_mapping Args: tests_path: should be in absolute path """ logger.info(f"make path: {tests_path}") test_files = [] if os.path.isdir(tests_path): files_list = load_folder_files(tests_path) test_files.extend(files_list) elif os.path.isfile(tests_path): test_files.append(tests_path) else: raise exceptions.TestcaseNotFound(f"Invalid tests path: {tests_path}") for test_file in test_files: if test_file.lower().endswith("_test.py"): pytest_files_run_set.add(test_file) continue try: test_content = load_test_file(test_file) except (exceptions.FileNotFound, exceptions.FileFormatError) as ex: logger.warning( f"Invalid test file: {test_file}\n{type(ex).__name__}: {ex}") continue if not isinstance(test_content, Dict): logger.warning(f"Invalid test file: {test_file}\n" f"reason: test content not in dict format.") continue # api in v2 format, convert to v3 testcase if "request" in test_content and "name" in test_content: test_content = ensure_testcase_v3_api(test_content) if "config" not in test_content: logger.warning(f"Invalid testcase/testsuite file: {test_file}\n" f"reason: missing config part.") continue elif not isinstance(test_content["config"], Dict): logger.warning( f"Invalid testcase/testsuite file: {test_file}\n" f"reason: config should be dict type, got {test_content['config']}" ) continue # ensure path absolute test_content.setdefault("config", {})["path"] = test_file # testcase if "teststeps" in test_content: try: testcase_pytest_path = make_testcase(test_content) pytest_files_run_set.add(testcase_pytest_path) except exceptions.TestCaseFormatError as ex: logger.warning( f"Invalid testcase file: {test_file}\n{type(ex).__name__}: {ex}" ) continue # testsuite elif "testcases" in test_content: try: make_testsuite(test_content) except exceptions.TestSuiteFormatError as ex: logger.warning( f"Invalid testsuite file: {test_file}\n{type(ex).__name__}: {ex}" ) continue # invalid format else: logger.warning( f"Invalid test file: {test_file}\n" f"reason: file content is neither testcase nor testsuite")