mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-07 23:41:22 +08:00
bugfix: make json serializable before rendering
This commit is contained in:
@@ -6,6 +6,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from httprunner import logger
|
from httprunner import logger
|
||||||
from jinja2 import Template
|
from jinja2 import Template
|
||||||
|
from requests.structures import CaseInsensitiveDict
|
||||||
|
|
||||||
|
|
||||||
def get_summary(result):
|
def get_summary(result):
|
||||||
@@ -38,6 +39,18 @@ def get_summary(result):
|
|||||||
|
|
||||||
return summary
|
return summary
|
||||||
|
|
||||||
|
def make_json_serializable(raw_json):
|
||||||
|
serializable_json = {}
|
||||||
|
for key, value in raw_json.items():
|
||||||
|
if isinstance(value, bytes):
|
||||||
|
value = value.decode("utf-8")
|
||||||
|
elif isinstance(value, CaseInsensitiveDict):
|
||||||
|
value = dict(value)
|
||||||
|
|
||||||
|
serializable_json[key] = value
|
||||||
|
|
||||||
|
return serializable_json
|
||||||
|
|
||||||
|
|
||||||
class HtmlTestResult(unittest.TextTestResult):
|
class HtmlTestResult(unittest.TextTestResult):
|
||||||
"""A html result class that can generate formatted html results.
|
"""A html result class that can generate formatted html results.
|
||||||
@@ -60,7 +73,7 @@ class HtmlTestResult(unittest.TextTestResult):
|
|||||||
'status': status,
|
'status': status,
|
||||||
'response_time': test.meta_data.get("response_time", 0),
|
'response_time': test.meta_data.get("response_time", 0),
|
||||||
'attachment': attachment,
|
'attachment': attachment,
|
||||||
"meta_data": test.meta_data
|
"meta_data": make_json_serializable(test.meta_data)
|
||||||
})
|
})
|
||||||
|
|
||||||
def startTestRun(self):
|
def startTestRun(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user