mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-06 08:19:45 +08:00
change: adjust code
This commit is contained in:
@@ -19,7 +19,8 @@ from httprunner.parser import parse_data
|
|||||||
"""
|
"""
|
||||||
make_files_cache_mapping: Dict[Text, List] = {}
|
make_files_cache_mapping: Dict[Text, List] = {}
|
||||||
|
|
||||||
__TMPL__ = """# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
|
__TEMPLATE__ = jinja2.Template(
|
||||||
|
"""# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
|
||||||
# FROM: {{ testcase_path }}
|
# FROM: {{ testcase_path }}
|
||||||
from httprunner import HttpRunner, TConfig, TStep
|
from httprunner import HttpRunner, TConfig, TStep
|
||||||
{% for import_str in imports_list %}
|
{% for import_str in imports_list %}
|
||||||
@@ -40,6 +41,7 @@ if __name__ == "__main__":
|
|||||||
{{ class_name }}().test_start()
|
{{ class_name }}().test_start()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def convert_testcase_path(testcase_path: Text) -> Tuple[Text, Text]:
|
def convert_testcase_path(testcase_path: Text) -> Tuple[Text, Text]:
|
||||||
@@ -75,7 +77,7 @@ def format_pytest_with_black(python_paths: List[Text]):
|
|||||||
logger.error(ex)
|
logger.error(ex)
|
||||||
|
|
||||||
|
|
||||||
def make_testcase(testcase: Dict) -> Union[str, None]:
|
def make_testcase(testcase: Dict) -> Text:
|
||||||
"""convert valid testcase dict to pytest file path"""
|
"""convert valid testcase dict to pytest file path"""
|
||||||
try:
|
try:
|
||||||
# validate testcase format
|
# validate testcase format
|
||||||
@@ -87,8 +89,6 @@ def make_testcase(testcase: Dict) -> Union[str, None]:
|
|||||||
testcase_path = testcase["config"]["path"]
|
testcase_path = testcase["config"]["path"]
|
||||||
logger.info(f"start to make testcase: {testcase_path}")
|
logger.info(f"start to make testcase: {testcase_path}")
|
||||||
|
|
||||||
template = jinja2.Template(__TMPL__)
|
|
||||||
|
|
||||||
# convert abs path to relative
|
# convert abs path to relative
|
||||||
if os.path.isabs(testcase_path):
|
if os.path.isabs(testcase_path):
|
||||||
testcase_path = testcase_path[len(os.getcwd()) + 1 :]
|
testcase_path = testcase_path[len(os.getcwd()) + 1 :]
|
||||||
@@ -139,7 +139,7 @@ def make_testcase(testcase: Dict) -> Union[str, None]:
|
|||||||
"teststeps": teststeps,
|
"teststeps": teststeps,
|
||||||
"imports_list": imports_list,
|
"imports_list": imports_list,
|
||||||
}
|
}
|
||||||
content = template.render(data)
|
content = __TEMPLATE__.render(data)
|
||||||
content = content.replace("'CLS_LB(", "").replace(")CLS_RB'", "")
|
content = content.replace("'CLS_LB(", "").replace(")CLS_RB'", "")
|
||||||
|
|
||||||
with open(testcase_python_path, "w", encoding="utf-8") as f:
|
with open(testcase_python_path, "w", encoding="utf-8") as f:
|
||||||
@@ -161,7 +161,6 @@ def make_testsuite(testsuite: Dict) -> List[Text]:
|
|||||||
config = testsuite["config"]
|
config = testsuite["config"]
|
||||||
testsuite_path = config["path"]
|
testsuite_path = config["path"]
|
||||||
project_meta = load_project_meta(testsuite_path)
|
project_meta = load_project_meta(testsuite_path)
|
||||||
project_working_directory = project_meta.PWD
|
|
||||||
|
|
||||||
testsuite_variables = config.get("variables", {})
|
testsuite_variables = config.get("variables", {})
|
||||||
if isinstance(testsuite_variables, Text):
|
if isinstance(testsuite_variables, Text):
|
||||||
@@ -173,7 +172,10 @@ def make_testsuite(testsuite: Dict) -> List[Text]:
|
|||||||
logger.info(f"start to make testsuite: {testsuite_path}")
|
logger.info(f"start to make testsuite: {testsuite_path}")
|
||||||
|
|
||||||
# create directory with testsuite file name, put its testcases under this directory
|
# create directory with testsuite file name, put its testcases under this directory
|
||||||
testsuite_dir = testsuite_path.replace(".", "_")
|
testsuite_dir = os.path.join(
|
||||||
|
os.path.dirname(testsuite_path),
|
||||||
|
os.path.basename(testsuite_path).replace(".", "_"),
|
||||||
|
)
|
||||||
os.makedirs(testsuite_dir, exist_ok=True)
|
os.makedirs(testsuite_dir, exist_ok=True)
|
||||||
|
|
||||||
testcase_files = []
|
testcase_files = []
|
||||||
@@ -181,7 +183,11 @@ def make_testsuite(testsuite: Dict) -> List[Text]:
|
|||||||
for testcase in testsuite["testcases"]:
|
for testcase in testsuite["testcases"]:
|
||||||
# get referenced testcase content
|
# get referenced testcase content
|
||||||
testcase_file = testcase["testcase"]
|
testcase_file = testcase["testcase"]
|
||||||
testcase_path = os.path.join(project_working_directory, testcase_file)
|
if os.path.isabs(testcase_file):
|
||||||
|
testcase_path = testcase_file
|
||||||
|
else:
|
||||||
|
testcase_path = os.path.join(project_meta.PWD, testcase_file)
|
||||||
|
|
||||||
testcase_dict = load_test_file(testcase_path)
|
testcase_dict = load_test_file(testcase_path)
|
||||||
testcase_dict.setdefault("config", {})
|
testcase_dict.setdefault("config", {})
|
||||||
testcase_dict["config"]["path"] = os.path.join(
|
testcase_dict["config"]["path"] = os.path.join(
|
||||||
@@ -206,7 +212,7 @@ def make_testsuite(testsuite: Dict) -> List[Text]:
|
|||||||
return testcase_files
|
return testcase_files
|
||||||
|
|
||||||
|
|
||||||
def __make(tests_path: Text) -> List:
|
def __make(tests_path: Text) -> List[Text]:
|
||||||
global make_files_cache_mapping
|
global make_files_cache_mapping
|
||||||
if tests_path in make_files_cache_mapping:
|
if tests_path in make_files_cache_mapping:
|
||||||
return make_files_cache_mapping[tests_path]
|
return make_files_cache_mapping[tests_path]
|
||||||
@@ -263,7 +269,6 @@ def __make(tests_path: Text) -> List:
|
|||||||
|
|
||||||
|
|
||||||
def main_make(tests_paths: List[Text]) -> List:
|
def main_make(tests_paths: List[Text]) -> List:
|
||||||
|
|
||||||
for tests_path in tests_paths:
|
for tests_path in tests_paths:
|
||||||
__make(tests_path)
|
__make(tests_path)
|
||||||
|
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ class HttpRunner(object):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
raise exceptions.ParamsError(
|
raise exceptions.ParamsError(
|
||||||
f"Invalid teststep referenced testcase: {step}"
|
f"Invalid teststep referenced testcase: {step.dict()}"
|
||||||
)
|
)
|
||||||
|
|
||||||
step_data.data = case_result.get_step_datas() # list of step data
|
step_data.data = case_result.get_step_datas() # list of step data
|
||||||
|
|||||||
Reference in New Issue
Block a user