mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 17:59:36 +08:00
feat: implement json dump Python objects when save tests
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
# Release History
|
# Release History
|
||||||
|
|
||||||
|
## 2.1.0 (2019-03-19)
|
||||||
|
|
||||||
|
**Features**
|
||||||
|
|
||||||
|
- implement json dump Python objects when save tests
|
||||||
|
|
||||||
## 2.0.6 (2019-03-18)
|
## 2.0.6 (2019-03-18)
|
||||||
|
|
||||||
**Features**
|
**Features**
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
__title__ = 'HttpRunner'
|
__title__ = 'HttpRunner'
|
||||||
__description__ = 'One-stop solution for HTTP(S) testing.'
|
__description__ = 'One-stop solution for HTTP(S) testing.'
|
||||||
__url__ = 'https://github.com/HttpRunner/HttpRunner'
|
__url__ = 'https://github.com/HttpRunner/HttpRunner'
|
||||||
__version__ = '2.0.6'
|
__version__ = '2.1.0'
|
||||||
__author__ = 'debugtalk'
|
__author__ = 'debugtalk'
|
||||||
__author_email__ = 'mail@debugtalk.com'
|
__author_email__ = 'mail@debugtalk.com'
|
||||||
__license__ = 'Apache-2.0'
|
__license__ = 'Apache-2.0'
|
||||||
|
|||||||
@@ -649,6 +649,13 @@ def omit_long_data(body, omit_len=512):
|
|||||||
def dump_json_file(json_data, pwd_dir_path, dump_file_name):
|
def dump_json_file(json_data, pwd_dir_path, dump_file_name):
|
||||||
""" dump json data to file
|
""" dump json data to file
|
||||||
"""
|
"""
|
||||||
|
class PythonObjectEncoder(json.JSONEncoder):
|
||||||
|
def default(self, obj):
|
||||||
|
try:
|
||||||
|
return super().default(self, obj)
|
||||||
|
except TypeError:
|
||||||
|
return str(obj)
|
||||||
|
|
||||||
logs_dir_path = os.path.join(pwd_dir_path, "logs")
|
logs_dir_path = os.path.join(pwd_dir_path, "logs")
|
||||||
if not os.path.isdir(logs_dir_path):
|
if not os.path.isdir(logs_dir_path):
|
||||||
os.makedirs(logs_dir_path)
|
os.makedirs(logs_dir_path)
|
||||||
@@ -663,7 +670,8 @@ def dump_json_file(json_data, pwd_dir_path, dump_file_name):
|
|||||||
json_data,
|
json_data,
|
||||||
indent=4,
|
indent=4,
|
||||||
separators=(',', ':'),
|
separators=(',', ':'),
|
||||||
ensure_ascii=False
|
ensure_ascii=False,
|
||||||
|
cls=PythonObjectEncoder
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -672,14 +680,15 @@ def dump_json_file(json_data, pwd_dir_path, dump_file_name):
|
|||||||
outfile,
|
outfile,
|
||||||
indent=4,
|
indent=4,
|
||||||
separators=(',', ':'),
|
separators=(',', ':'),
|
||||||
ensure_ascii=False
|
ensure_ascii=False,
|
||||||
|
cls=PythonObjectEncoder
|
||||||
)
|
)
|
||||||
|
|
||||||
msg = "dump file: {}".format(dump_file_path)
|
msg = "dump file: {}".format(dump_file_path)
|
||||||
logger.color_print(msg, "BLUE")
|
logger.color_print(msg, "BLUE")
|
||||||
|
|
||||||
except TypeError:
|
except TypeError as ex:
|
||||||
msg = "Failed to dump json file: {}".format(dump_file_path)
|
msg = "Failed to dump json file: {}\nReason: {}".format(dump_file_path, ex)
|
||||||
logger.color_print(msg, "RED")
|
logger.color_print(msg, "RED")
|
||||||
|
|
||||||
|
|
||||||
@@ -711,14 +720,13 @@ def dump_tests(tests_mapping, tag_name):
|
|||||||
}
|
}
|
||||||
|
|
||||||
for key in project_mapping:
|
for key in project_mapping:
|
||||||
if key != "functions":
|
if key == "functions" and project_mapping["functions"]:
|
||||||
|
tests_to_dump["project_mapping"]["debugtalk.py"] = {
|
||||||
|
"path": os.path.join(pwd_dir_path, "debugtalk.py"),
|
||||||
|
"functions": project_mapping["functions"]
|
||||||
|
}
|
||||||
|
else:
|
||||||
tests_to_dump["project_mapping"][key] = project_mapping[key]
|
tests_to_dump["project_mapping"][key] = project_mapping[key]
|
||||||
continue
|
|
||||||
|
|
||||||
# remove functions in order to dump
|
|
||||||
if project_mapping["functions"]:
|
|
||||||
debugtalk_py_path = os.path.join(pwd_dir_path, "debugtalk.py")
|
|
||||||
tests_to_dump["project_mapping"]["debugtalk.py"] = debugtalk_py_path
|
|
||||||
|
|
||||||
if "api" in tests_mapping:
|
if "api" in tests_mapping:
|
||||||
tests_to_dump["api"] = tests_mapping["api"]
|
tests_to_dump["api"] = tests_mapping["api"]
|
||||||
|
|||||||
Reference in New Issue
Block a user