mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 08:59:44 +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] = {}
|
||||
|
||||
__TMPL__ = """# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
|
||||
__TEMPLATE__ = jinja2.Template(
|
||||
"""# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
|
||||
# FROM: {{ testcase_path }}
|
||||
from httprunner import HttpRunner, TConfig, TStep
|
||||
{% for import_str in imports_list %}
|
||||
@@ -40,6 +41,7 @@ if __name__ == "__main__":
|
||||
{{ class_name }}().test_start()
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def make_testcase(testcase: Dict) -> Union[str, None]:
|
||||
def make_testcase(testcase: Dict) -> Text:
|
||||
"""convert valid testcase dict to pytest file path"""
|
||||
try:
|
||||
# validate testcase format
|
||||
@@ -87,8 +89,6 @@ def make_testcase(testcase: Dict) -> Union[str, None]:
|
||||
testcase_path = testcase["config"]["path"]
|
||||
logger.info(f"start to make testcase: {testcase_path}")
|
||||
|
||||
template = jinja2.Template(__TMPL__)
|
||||
|
||||
# convert abs path to relative
|
||||
if os.path.isabs(testcase_path):
|
||||
testcase_path = testcase_path[len(os.getcwd()) + 1 :]
|
||||
@@ -139,7 +139,7 @@ def make_testcase(testcase: Dict) -> Union[str, None]:
|
||||
"teststeps": teststeps,
|
||||
"imports_list": imports_list,
|
||||
}
|
||||
content = template.render(data)
|
||||
content = __TEMPLATE__.render(data)
|
||||
content = content.replace("'CLS_LB(", "").replace(")CLS_RB'", "")
|
||||
|
||||
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"]
|
||||
testsuite_path = config["path"]
|
||||
project_meta = load_project_meta(testsuite_path)
|
||||
project_working_directory = project_meta.PWD
|
||||
|
||||
testsuite_variables = config.get("variables", {})
|
||||
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}")
|
||||
|
||||
# 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)
|
||||
|
||||
testcase_files = []
|
||||
@@ -181,7 +183,11 @@ def make_testsuite(testsuite: Dict) -> List[Text]:
|
||||
for testcase in testsuite["testcases"]:
|
||||
# get referenced testcase content
|
||||
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.setdefault("config", {})
|
||||
testcase_dict["config"]["path"] = os.path.join(
|
||||
@@ -206,7 +212,7 @@ def make_testsuite(testsuite: Dict) -> List[Text]:
|
||||
return testcase_files
|
||||
|
||||
|
||||
def __make(tests_path: Text) -> List:
|
||||
def __make(tests_path: Text) -> List[Text]:
|
||||
global make_files_cache_mapping
|
||||
if tests_path in make_files_cache_mapping:
|
||||
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:
|
||||
|
||||
for tests_path in tests_paths:
|
||||
__make(tests_path)
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ class HttpRunner(object):
|
||||
|
||||
else:
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user