fix teardown_hook对response的修改体现在测试报告上 httprunner#430

This commit is contained in:
fengyu
2019-11-05 14:12:30 +08:00
parent ed5269ba98
commit d5457c040a
2 changed files with 13 additions and 2 deletions

View File

@@ -8,7 +8,7 @@ from requests import Request, Response
from requests.exceptions import (InvalidSchema, InvalidURL, MissingSchema,
RequestException)
from httprunner import logger
from httprunner import logger, response
from httprunner.utils import lower_dict_keys, omit_long_data
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
@@ -115,7 +115,10 @@ class HttpSession(requests.Session):
else:
try:
# try to record json data
req_resp_dict["response"]["json"] = resp_obj.json()
if isinstance(resp_obj, response.ResponseObject):
req_resp_dict["response"]["json"] = resp_obj.json
else:
req_resp_dict["response"]["json"] = resp_obj.json()
except ValueError:
# only record at most 512 text charactors
resp_text = resp_obj.text
@@ -126,6 +129,13 @@ class HttpSession(requests.Session):
return req_resp_dict
def update_last_req_resp_record(self, resp_obj):
"""
update request and response info from Response() object.
"""
self.meta_data["data"].pop()
self.meta_data["data"].append(self.get_req_resp_record(resp_obj))
def request(self, method, url, name=None, **kwargs):
"""
Constructs and sends a :py:class:`requests.Request`.

View File

@@ -260,6 +260,7 @@ class Runner(object):
if teardown_hooks:
self.session_context.update_test_variables("response", resp_obj)
self.do_hook_actions(teardown_hooks, "teardown")
self.http_client_session.update_last_req_resp_record(resp_obj)
# extract
extractors = test_dict.get("extract", {})