Пример #1
0
def load_project_meta(test_path: Text, reload: bool = False) -> ProjectMeta:
    """ load api, testcases, .env, debugtalk.py functions.
        api/testcases folder is relative to project_working_directory
        by default, project_meta will be loaded only once, unless set reload to true.

    Args:
        test_path (str): test file/folder path, locate pwd from this path.
        reload: reload project meta if set true, default to false

    Returns:
        project loaded api/testcases definitions,
            environments and debugtalk.py functions.

    """
    global project_meta
    if project_meta and (not reload):
        return project_meta

    project_meta = ProjectMeta()

    if not test_path:
        return project_meta

    debugtalk_path, project_working_directory = locate_project_working_directory(
        test_path
    )

    # add PWD to sys.path
    sys.path.insert(0, project_working_directory)

    # load .env file
    # NOTICE:
    # environment variable maybe loaded in debugtalk.py
    # thus .env file should be loaded before loading debugtalk.py
    dot_env_path = os.path.join(project_working_directory, ".env")
    project_meta.env = load_dot_env_file(dot_env_path)

    if debugtalk_path:
        # load debugtalk.py functions
        debugtalk_functions = load_debugtalk_functions()
    else:
        debugtalk_functions = {}

    # locate PWD and load debugtalk.py functions
    project_meta.PWD = project_working_directory
    project_meta.functions = debugtalk_functions
    project_meta.test_path = os.path.abspath(test_path)[
        len(project_working_directory) + 1 :
    ]

    return project_meta
Пример #2
0
def load_project_meta(test_path: Text) -> ProjectMeta:
    """ load api, testcases, .env, debugtalk.py functions.
        api/testcases folder is relative to project_working_directory

    Args:
        test_path (str): test file/folder path, locate pwd from this path.

    Returns:
        project loaded api/testcases definitions,
            environments and debugtalk.py functions.

    """
    project_meta = ProjectMeta()

    if not test_path:
        return project_meta

    if test_path in project_meta_cached_mapping:
        return project_meta_cached_mapping[test_path]

    debugtalk_path, project_working_directory = init_project_working_directory(
        test_path)

    # load .env file
    # NOTICE:
    # environment variable maybe loaded in debugtalk.py
    # thus .env file should be loaded before loading debugtalk.py
    dot_env_path = os.path.join(project_working_directory, ".env")
    project_meta.env = load_dot_env_file(dot_env_path)

    if debugtalk_path:
        # load debugtalk.py functions
        debugtalk_functions = load_debugtalk_functions()
    else:
        debugtalk_functions = {}

    # locate PWD and load debugtalk.py functions
    project_meta.PWD = project_working_directory
    project_meta.functions = debugtalk_functions
    project_meta.test_path = os.path.abspath(
        test_path)[len(project_working_directory) + 1:]

    project_meta_cached_mapping[test_path] = project_meta
    return project_meta