1解取、init.py有這個(gè)文件霞势,則證明這個(gè)目錄可以當(dāng)做包進(jìn)行引用
2晕城、init.py這個(gè)文件中的all數(shù)組則代表能引用的方法在此聲明泞坦,若別人引用該包中的函數(shù),這個(gè)函數(shù)不在all中砖顷,可能會(huì)報(bào)錯(cuò)
以httprunner中源碼為例,httprunner中的的loader目錄為例赃梧,目錄結(jié)構(gòu)滤蝠,如圖:
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中授嘀,所以可能報(bào)錯(cuò)