1、init.py有这个文件,则证明这个目录可以当做包进行引用
2、init.py这个文件中的all数组则代表能引用的方法在此声明,若别人引用该包中的函数,这个函数不在all中,可能会报错
以httprunner中源码为例,httprunner中的的loader目录为例,目录结构,如图:
image.png
from httprunner.loader.check import is_test_path, is_test_content, JsonSchemaChecker
from httprunner.loader.locate import get_project_working_directory as get_pwd
from httprunner.loader.load import load_csv_file, load_builtin_functions
from httprunner.loader.buildup import load_cases, load_project_data
__all__ = [
"is_test_path",
"is_test_content",
"JsonSchemaChecker",
"get_pwd",
"load_csv_file",
"load_builtin_functions",
"load_project_data",
"load_cases"
]
引用:
from httprunner.loader import *
from httprunner.loader import load_cases
from httprunner.loader import validate_format #也是loader目录下的,但是不在all中,所以可能报错
网友评论