(testsuite: Dict)
convert valid testsuite dict to pytest folder with testcases
convert valid testsuite dict to pytest folder with testcases
convert valid testsuite dict to pytest folder with testcases
def make_testsuite(testsuite: Dict) -> NoReturn:
    """convert valid testsuite dict to pytest folder with testcases"""
    # validate testsuite format
    load_testsuite(testsuite)

    testsuite_config = testsuite["config"]
    testsuite_path = testsuite_config["path"]
    testsuite_variables = convert_variables(
        testsuite_config.get("variables", {}), testsuite_path
    )

    logger.info(f"start to make testsuite: {testsuite_path}")

    # create directory with testsuite file name, put its testcases under this directory
    testsuite_path = ensure_file_abs_path_valid(testsuite_path)
    testsuite_dir, file_suffix = os.path.splitext(testsuite_path)
    # demo_testsuite.yml => demo_testsuite_yml
    testsuite_dir = f"{testsuite_dir}_{file_suffix.lstrip('.')}"

    for testcase in testsuite["testcases"]:
        # get referenced testcase content
        testcase_file = testcase["testcase"]
        testcase_path = __ensure_absolute(testcase_file)
        testcase_dict = load_test_file(testcase_path)
        testcase_dict.setdefault("config", {})
        testcase_dict["config"]["path"] = testcase_path

        # override testcase name
        testcase_dict["config"]["name"] = testcase["name"]
        # override base_url
        base_url = testsuite_config.get("base_url") or testcase.get("base_url")
        if base_url:
            testcase_dict["config"]["base_url"] = base_url
        # override verify
        if "verify" in testsuite_config:
            testcase_dict["config"]["verify"] = testsuite_config["verify"]
        # override variables
        # testsuite testcase variables > testsuite config variables
        testcase_variables = convert_variables(
            testcase.get("variables", {}), testcase_path
        )
        testcase_variables = merge_variables(testcase_variables, testsuite_variables)
        # testsuite testcase variables > testcase config variables
        testcase_dict["config"]["variables"] = convert_variables(
            testcase_dict["config"].get("variables", {}), testcase_path
        )
        testcase_dict["config"]["variables"].update(testcase_variables)

        # override weight
        if "weight" in testcase:
            testcase_dict["config"]["weight"] = testcase["weight"]

        # make testcase
        testcase_pytest_path = make_testcase(testcase_dict, testsuite_dir)
        pytest_files_run_set.add(testcase_pytest_path)
def make_testsuite ( testsuite : Dict ) -> NoReturn : # validate testsuite format load_testsuite ( testsuite ) testsuite_config = testsuite [ "config" ] testsuite_path = testsuite_config [ "path" ] testsuite_variables = convert_variables ( testsuite_config . get ( "variables" , { } ) , testsuite_path ) logger . info ( f"start to make testsuite: {testsuite_path}" ) # create directory with testsuite file name, put its testcases under this directory testsuite_path = ensure_file_abs_path_valid ( testsuite_path ) testsuite_dir , file_suffix = os . path . splitext ( testsuite_path ) # demo_testsuite.yml => demo_testsuite_yml testsuite_dir = f"{testsuite_dir}_{file_suffix.lstrip('.')}" for testcase in testsuite [ "testcases" ] : # get referenced testcase content testcase_file = testcase [ "testcase" ] testcase_path = __ensure_absolute ( testcase_file ) testcase_dict = load_test_file ( testcase_path ) testcase_dict . setdefault ( "config" , { } ) testcase_dict [ "config" ] [ "path" ] = testcase_path # override testcase name testcase_dict [ "config" ] [ "name" ] = testcase [ "name" ] # override base_url base_url = testsuite_config . get ( "base_url" ) or testcase . get ( "base_url" ) if base_url : testcase_dict [ "config" ] [ "base_url" ] = base_url # override verify if "verify" in testsuite_config : testcase_dict [ "config" ] [ "verify" ] = testsuite_config [ "verify" ] # override variables # testsuite testcase variables > testsuite config variables testcase_variables = convert_variables ( testcase . get ( "variables" , { } ) , testcase_path ) testcase_variables = merge_variables ( testcase_variables , testsuite_variables ) # testsuite testcase variables > testcase config variables testcase_dict [ "config" ] [ "variables" ] = convert_variables ( testcase_dict [ "config" ] . get ( "variables" , { } ) , testcase_path ) testcase_dict [ "config" ] [ "variables" ] . update ( testcase_variables ) # override weight if "weight" in testcase : testcase_dict [ "config" ] [ "weight" ] = testcase [ "weight" ] # make testcase testcase_pytest_path = make_testcase ( testcase_dict , testsuite_dir ) pytest_files_run_set . add ( testcase_pytest_path )