change: rename PWD to project RootDir

This commit is contained in:
debugtalk
2020-06-06 21:17:00 +08:00
parent 6471b006cb
commit e2703fff32
6 changed files with 29 additions and 29 deletions

View File

@@ -220,7 +220,7 @@ def generate_conftest_for_summary(args: List):
sys.exit(1)
project_meta = load_project_meta(test_path)
conftest_path = os.path.join(project_meta.PWD, "conftest.py")
conftest_path = os.path.join(project_meta.RootDir, "conftest.py")
if os.path.isfile(conftest_path):
return
@@ -291,8 +291,8 @@ def session_fixture(request):
'''
test_path = os.path.abspath(test_path)
logs_dir_path = os.path.join(project_meta.PWD, "logs")
test_path_relative_path = test_path[len(project_meta.PWD) + 1 :]
logs_dir_path = os.path.join(project_meta.RootDir, "logs")
test_path_relative_path = test_path[len(project_meta.RootDir) + 1 :]
if os.path.isdir(test_path):
file_foder_path = os.path.join(logs_dir_path, test_path_relative_path)

View File

@@ -139,7 +139,7 @@ def multipart_encoder(**kwargs):
project_meta = load_project_meta(os.getcwd())
_file_path = os.path.join(project_meta.PWD, value)
_file_path = os.path.join(project_meta.RootDir, value)
is_exists_file = os.path.isfile(_file_path)
if is_exists_file:

View File

@@ -176,7 +176,7 @@ def load_csv_file(csv_file: Text) -> List[Dict]:
raise exceptions.MyBaseFailure("load_project_meta() has not been called!")
# make compatible with Windows/Linux
csv_file = os.path.join(project_meta.PWD, *csv_file.split("/"))
csv_file = os.path.join(project_meta.RootDir, *csv_file.split("/"))
if not os.path.isfile(csv_file):
# file path not exist
@@ -327,14 +327,14 @@ def locate_debugtalk_py(start_path: Text) -> Text:
return debugtalk_path
def locate_project_working_directory(test_path: Text) -> Tuple[Text, Text]:
""" locate debugtalk.py path as project working directory
def locate_project_root_directory(test_path: Text) -> Tuple[Text, Text]:
""" locate debugtalk.py path as project root directory
Args:
test_path: specified testfile path
Returns:
(str, str): debugtalk.py path, project_working_directory
(str, str): debugtalk.py path, project_root_directory
"""
@@ -355,18 +355,18 @@ def locate_project_working_directory(test_path: Text) -> Tuple[Text, Text]:
debugtalk_path = locate_debugtalk_py(test_path)
if debugtalk_path:
# The folder contains debugtalk.py will be treated as PWD.
project_working_directory = os.path.dirname(debugtalk_path)
# The folder contains debugtalk.py will be treated as project RootDir.
project_root_directory = os.path.dirname(debugtalk_path)
else:
# debugtalk.py not found, use os.getcwd() as PWD.
project_working_directory = os.getcwd()
# debugtalk.py not found, use os.getcwd() as project RootDir.
project_root_directory = os.getcwd()
return debugtalk_path, project_working_directory
return debugtalk_path, project_root_directory
def load_debugtalk_functions() -> Dict[Text, Callable]:
""" load project debugtalk.py module functions
debugtalk.py should be located in project working directory.
debugtalk.py should be located in project root directory.
Returns:
dict: debugtalk module functions mapping
@@ -382,12 +382,12 @@ def load_debugtalk_functions() -> Dict[Text, Callable]:
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
""" load testcases, .env, debugtalk.py functions.
testcases folder is relative to project_root_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.
test_path (str): test file/folder path, locate project RootDir from this path.
reload: reload project meta if set true, default to false
Returns:
@@ -404,18 +404,16 @@ def load_project_meta(test_path: Text, reload: bool = False) -> ProjectMeta:
if not test_path:
return project_meta
debugtalk_path, project_working_directory = locate_project_working_directory(
test_path
)
debugtalk_path, project_root_directory = locate_project_root_directory(test_path)
# add PWD to sys.path
sys.path.insert(0, project_working_directory)
# add project RootDir to sys.path
sys.path.insert(0, project_root_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")
dot_env_path = os.path.join(project_root_directory, ".env")
dot_env = load_dot_env_file(dot_env_path)
if dot_env:
project_meta.env = dot_env
@@ -427,8 +425,8 @@ def load_project_meta(test_path: Text, reload: bool = False) -> ProjectMeta:
else:
debugtalk_functions = {}
# locate PWD and load debugtalk.py functions
project_meta.PWD = project_working_directory
# locate project RootDir and load debugtalk.py functions
project_meta.RootDir = project_root_directory
project_meta.functions = debugtalk_functions
project_meta.debugtalk_path = debugtalk_path

View File

@@ -64,7 +64,7 @@ def __ensure_absolute(path: Text) -> Text:
if os.path.isabs(path):
absolute_path = path
else:
absolute_path = os.path.join(project_meta.PWD, path)
absolute_path = os.path.join(project_meta.RootDir, path)
if not os.path.isfile(absolute_path):
raise exceptions.ParamsError(f"Invalid testcase file path: {absolute_path}")

View File

@@ -85,7 +85,7 @@ class ProjectMeta(BaseModel):
dot_env_path: Text = "" # .env file path
functions: FunctionsMapping = {} # functions defined in debugtalk.py
env: Env = {}
PWD: Text = os.getcwd() # project working directory, the path debugtalk.py located
RootDir: Text = os.getcwd() # project root directory, the path debugtalk.py located
class TestsMapping(BaseModel):

View File

@@ -187,7 +187,9 @@ class HttpRunner(object):
if os.path.isabs(step.testcase):
ref_testcase_path = step.testcase
else:
ref_testcase_path = os.path.join(self.__project_meta.PWD, step.testcase)
ref_testcase_path = os.path.join(
self.__project_meta.RootDir, step.testcase
)
case_result = (
HttpRunner()
@@ -349,7 +351,7 @@ class HttpRunner(object):
)
self.__case_id = self.__case_id or str(uuid.uuid4())
self.__log_path = self.__log_path or os.path.join(
self.__project_meta.PWD, "logs", f"{self.__case_id}.run.log"
self.__project_meta.RootDir, "logs", f"{self.__case_id}.run.log"
)
log_handler = logger.add(self.__log_path, level="DEBUG")