mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 17:29:56 +08:00
refactor: is_test_path
This commit is contained in:
@@ -289,7 +289,7 @@ class HttpRunner(object):
|
||||
|
||||
"""
|
||||
logger.log_info("HttpRunner version: {}".format(__version__))
|
||||
if loader.is_testcase_path(path_or_tests):
|
||||
if loader.is_test_path(path_or_tests):
|
||||
return self.run_path(path_or_tests, dot_env_path, mapping)
|
||||
elif loader.is_testcases(path_or_tests):
|
||||
return self.run_tests(path_or_tests)
|
||||
|
||||
@@ -8,13 +8,13 @@ HttpRunner loader
|
||||
|
||||
"""
|
||||
|
||||
from httprunner.loader.check import is_testcase_path, is_testcases, JsonSchemaChecker
|
||||
from httprunner.loader.check import is_test_path, is_testcases, 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_testcase_path",
|
||||
"is_test_path",
|
||||
"is_testcases",
|
||||
"JsonSchemaChecker",
|
||||
"get_pwd",
|
||||
|
||||
@@ -175,30 +175,43 @@ def is_testcases(data_structure):
|
||||
return True
|
||||
|
||||
|
||||
def is_testcase_path(path):
|
||||
""" check if path is testcase path or path list.
|
||||
def is_test_path(path):
|
||||
""" check if path is valid json/yaml file path or a existed directory.
|
||||
|
||||
Args:
|
||||
path (str/list): file path or file path list.
|
||||
path (str/list/tuple): file path/directory or file path list.
|
||||
|
||||
Returns:
|
||||
bool: True if path is valid file path or path list, otherwise False.
|
||||
|
||||
"""
|
||||
if not isinstance(path, (str, list)):
|
||||
if not isinstance(path, (str, list, tuple)):
|
||||
return False
|
||||
|
||||
if isinstance(path, list):
|
||||
elif isinstance(path, (list, tuple)):
|
||||
for p in path:
|
||||
if not is_testcase_path(p):
|
||||
if not is_test_path(p):
|
||||
return False
|
||||
|
||||
if isinstance(path, str):
|
||||
return True
|
||||
|
||||
else:
|
||||
# path is string
|
||||
if not os.path.exists(path):
|
||||
return False
|
||||
|
||||
file_suffix = os.path.splitext(path)[1].lower()
|
||||
if file_suffix != ['.json', '.yaml', '.yml']:
|
||||
# path exists
|
||||
if os.path.isfile(path):
|
||||
# path is a file
|
||||
file_suffix = os.path.splitext(path)[1].lower()
|
||||
if file_suffix not in ['.json', '.yaml', '.yml']:
|
||||
# path is not json/yaml file
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
elif os.path.isdir(path):
|
||||
# path is a directory
|
||||
return True
|
||||
else:
|
||||
# path is neither a folder nor a file, maybe a symbol link or something else
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user