mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 07:57:27 +08:00
change: rename PWD to project RootDir
This commit is contained in:
@@ -220,7 +220,7 @@ def generate_conftest_for_summary(args: List):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
project_meta = load_project_meta(test_path)
|
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):
|
if os.path.isfile(conftest_path):
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -291,8 +291,8 @@ def session_fixture(request):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
test_path = os.path.abspath(test_path)
|
test_path = os.path.abspath(test_path)
|
||||||
logs_dir_path = os.path.join(project_meta.PWD, "logs")
|
logs_dir_path = os.path.join(project_meta.RootDir, "logs")
|
||||||
test_path_relative_path = test_path[len(project_meta.PWD) + 1 :]
|
test_path_relative_path = test_path[len(project_meta.RootDir) + 1 :]
|
||||||
|
|
||||||
if os.path.isdir(test_path):
|
if os.path.isdir(test_path):
|
||||||
file_foder_path = os.path.join(logs_dir_path, test_path_relative_path)
|
file_foder_path = os.path.join(logs_dir_path, test_path_relative_path)
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ def multipart_encoder(**kwargs):
|
|||||||
|
|
||||||
project_meta = load_project_meta(os.getcwd())
|
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)
|
is_exists_file = os.path.isfile(_file_path)
|
||||||
|
|
||||||
if is_exists_file:
|
if is_exists_file:
|
||||||
|
|||||||
+19
-21
@@ -176,7 +176,7 @@ def load_csv_file(csv_file: Text) -> List[Dict]:
|
|||||||
raise exceptions.MyBaseFailure("load_project_meta() has not been called!")
|
raise exceptions.MyBaseFailure("load_project_meta() has not been called!")
|
||||||
|
|
||||||
# make compatible with Windows/Linux
|
# 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):
|
if not os.path.isfile(csv_file):
|
||||||
# file path not exist
|
# file path not exist
|
||||||
@@ -327,14 +327,14 @@ def locate_debugtalk_py(start_path: Text) -> Text:
|
|||||||
return debugtalk_path
|
return debugtalk_path
|
||||||
|
|
||||||
|
|
||||||
def locate_project_working_directory(test_path: Text) -> Tuple[Text, Text]:
|
def locate_project_root_directory(test_path: Text) -> Tuple[Text, Text]:
|
||||||
""" locate debugtalk.py path as project working directory
|
""" locate debugtalk.py path as project root directory
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
test_path: specified testfile path
|
test_path: specified testfile path
|
||||||
|
|
||||||
Returns:
|
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)
|
debugtalk_path = locate_debugtalk_py(test_path)
|
||||||
|
|
||||||
if debugtalk_path:
|
if debugtalk_path:
|
||||||
# The folder contains debugtalk.py will be treated as PWD.
|
# The folder contains debugtalk.py will be treated as project RootDir.
|
||||||
project_working_directory = os.path.dirname(debugtalk_path)
|
project_root_directory = os.path.dirname(debugtalk_path)
|
||||||
else:
|
else:
|
||||||
# debugtalk.py not found, use os.getcwd() as PWD.
|
# debugtalk.py not found, use os.getcwd() as project RootDir.
|
||||||
project_working_directory = os.getcwd()
|
project_root_directory = os.getcwd()
|
||||||
|
|
||||||
return debugtalk_path, project_working_directory
|
return debugtalk_path, project_root_directory
|
||||||
|
|
||||||
|
|
||||||
def load_debugtalk_functions() -> Dict[Text, Callable]:
|
def load_debugtalk_functions() -> Dict[Text, Callable]:
|
||||||
""" load project debugtalk.py module functions
|
""" 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:
|
Returns:
|
||||||
dict: debugtalk module functions mapping
|
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:
|
def load_project_meta(test_path: Text, reload: bool = False) -> ProjectMeta:
|
||||||
""" load api, testcases, .env, debugtalk.py functions.
|
""" load testcases, .env, debugtalk.py functions.
|
||||||
api/testcases folder is relative to project_working_directory
|
testcases folder is relative to project_root_directory
|
||||||
by default, project_meta will be loaded only once, unless set reload to true.
|
by default, project_meta will be loaded only once, unless set reload to true.
|
||||||
|
|
||||||
Args:
|
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
|
reload: reload project meta if set true, default to false
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -404,18 +404,16 @@ def load_project_meta(test_path: Text, reload: bool = False) -> ProjectMeta:
|
|||||||
if not test_path:
|
if not test_path:
|
||||||
return project_meta
|
return project_meta
|
||||||
|
|
||||||
debugtalk_path, project_working_directory = locate_project_working_directory(
|
debugtalk_path, project_root_directory = locate_project_root_directory(test_path)
|
||||||
test_path
|
|
||||||
)
|
|
||||||
|
|
||||||
# add PWD to sys.path
|
# add project RootDir to sys.path
|
||||||
sys.path.insert(0, project_working_directory)
|
sys.path.insert(0, project_root_directory)
|
||||||
|
|
||||||
# load .env file
|
# load .env file
|
||||||
# NOTICE:
|
# NOTICE:
|
||||||
# environment variable maybe loaded in debugtalk.py
|
# environment variable maybe loaded in debugtalk.py
|
||||||
# thus .env file should be loaded before loading 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)
|
dot_env = load_dot_env_file(dot_env_path)
|
||||||
if dot_env:
|
if dot_env:
|
||||||
project_meta.env = dot_env
|
project_meta.env = dot_env
|
||||||
@@ -427,8 +425,8 @@ def load_project_meta(test_path: Text, reload: bool = False) -> ProjectMeta:
|
|||||||
else:
|
else:
|
||||||
debugtalk_functions = {}
|
debugtalk_functions = {}
|
||||||
|
|
||||||
# locate PWD and load debugtalk.py functions
|
# locate project RootDir and load debugtalk.py functions
|
||||||
project_meta.PWD = project_working_directory
|
project_meta.RootDir = project_root_directory
|
||||||
project_meta.functions = debugtalk_functions
|
project_meta.functions = debugtalk_functions
|
||||||
project_meta.debugtalk_path = debugtalk_path
|
project_meta.debugtalk_path = debugtalk_path
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ def __ensure_absolute(path: Text) -> Text:
|
|||||||
if os.path.isabs(path):
|
if os.path.isabs(path):
|
||||||
absolute_path = path
|
absolute_path = path
|
||||||
else:
|
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):
|
if not os.path.isfile(absolute_path):
|
||||||
raise exceptions.ParamsError(f"Invalid testcase file path: {absolute_path}")
|
raise exceptions.ParamsError(f"Invalid testcase file path: {absolute_path}")
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class ProjectMeta(BaseModel):
|
|||||||
dot_env_path: Text = "" # .env file path
|
dot_env_path: Text = "" # .env file path
|
||||||
functions: FunctionsMapping = {} # functions defined in debugtalk.py
|
functions: FunctionsMapping = {} # functions defined in debugtalk.py
|
||||||
env: Env = {}
|
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):
|
class TestsMapping(BaseModel):
|
||||||
|
|||||||
@@ -187,7 +187,9 @@ class HttpRunner(object):
|
|||||||
if os.path.isabs(step.testcase):
|
if os.path.isabs(step.testcase):
|
||||||
ref_testcase_path = step.testcase
|
ref_testcase_path = step.testcase
|
||||||
else:
|
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 = (
|
case_result = (
|
||||||
HttpRunner()
|
HttpRunner()
|
||||||
@@ -349,7 +351,7 @@ class HttpRunner(object):
|
|||||||
)
|
)
|
||||||
self.__case_id = self.__case_id or str(uuid.uuid4())
|
self.__case_id = self.__case_id or str(uuid.uuid4())
|
||||||
self.__log_path = self.__log_path or os.path.join(
|
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")
|
log_handler = logger.add(self.__log_path, level="DEBUG")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user