diff --git a/httprunner/utils.py b/httprunner/utils.py index 77515177..dc6f8f14 100644 --- a/httprunner/utils.py +++ b/httprunner/utils.py @@ -585,6 +585,7 @@ def prettify_json_file(file_list): def dump_tests(tests_mapping, tag_name): """ dump all tests data (except functions) to json file. + the dumped files are located in PWD/logs folder. Args: tests_mapping (dict): data to dump @@ -593,20 +594,27 @@ def dump_tests(tests_mapping, tag_name): """ project_mapping = tests_mapping.get("project_mapping", {}) test_path = project_mapping.get("test_path") or "tests_mapping" - dir_path = project_mapping.get("PWD") or os.getcwd() + pwd_dir_path = project_mapping.get("PWD") or os.getcwd() file_name, file_suffix = os.path.splitext(os.path.basename(test_path)) - dump_file_path = os.path.join(dir_path, "{}.{}.json".format(file_name, tag_name)) - tests_to_dump = {} + logs_dir_path = os.path.join(pwd_dir_path, "logs") + if not os.path.isdir(logs_dir_path): + os.makedirs(logs_dir_path) + + dump_file_path = os.path.join(logs_dir_path, "{}.{}.json".format(file_name, tag_name)) + + tests_to_dump = { + "project_mapping": {} + } for key in project_mapping: if key != "functions": - tests_to_dump[key] = project_mapping[key] + tests_to_dump["project_mapping"][key] = project_mapping[key] continue if project_mapping["functions"]: - debugtalk_py_path = os.path.join(dir_path, "debugtalk.py") - tests_to_dump["debugtalk.py"] = debugtalk_py_path + debugtalk_py_path = os.path.join(pwd_dir_path, "debugtalk.py") + tests_to_dump["project_mapping"]["debugtalk.py"] = debugtalk_py_path tests_to_dump["testcases"] = tests_mapping["testcases"]