mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-06 00:09:37 +08:00
make logging string unicode
This commit is contained in:
@@ -136,7 +136,7 @@ class HttpSession(requests.Session):
|
|||||||
try:
|
try:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except RequestException as e:
|
except RequestException as e:
|
||||||
logging.error(" Failed to {method} {url}! exception msg: {exception}".format(
|
logging.error(u" Failed to {method} {url}! exception msg: {exception}".format(
|
||||||
method=method, url=url, exception=str(e)))
|
method=method, url=url, exception=str(e)))
|
||||||
else:
|
else:
|
||||||
logging.info(
|
logging.info(
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ class ResponseObject(object):
|
|||||||
"""
|
"""
|
||||||
matched = re.search(field, self.resp_text)
|
matched = re.search(field, self.resp_text)
|
||||||
if not matched:
|
if not matched:
|
||||||
err_msg = "Extractor error: failed to extract data with regex!\n"
|
err_msg = u"Extractor error: failed to extract data with regex!\n"
|
||||||
err_msg += "response body: {}\n".format(self.resp_text)
|
err_msg += u"response body: {}\n".format(self.resp_text)
|
||||||
err_msg += "regex: {}\n".format(field)
|
err_msg += u"regex: {}\n".format(field)
|
||||||
logging.error(err_msg)
|
logging.error(err_msg)
|
||||||
raise exception.ParamsError(err_msg)
|
raise exception.ParamsError(err_msg)
|
||||||
|
|
||||||
@@ -75,9 +75,9 @@ class ResponseObject(object):
|
|||||||
|
|
||||||
if sub_query:
|
if sub_query:
|
||||||
if not isinstance(top_query_content, (dict, CaseInsensitiveDict, list)):
|
if not isinstance(top_query_content, (dict, CaseInsensitiveDict, list)):
|
||||||
err_msg = "Extractor error: failed to extract data with regex!\n"
|
err_msg = u"Extractor error: failed to extract data with regex!\n"
|
||||||
err_msg += "response: {}\n".format(self.parsed_dict())
|
err_msg += u"response: {}\n".format(self.parsed_dict())
|
||||||
err_msg += "regex: {}\n".format(field)
|
err_msg += u"regex: {}\n".format(field)
|
||||||
logging.error(err_msg)
|
logging.error(err_msg)
|
||||||
raise exception.ParamsError(err_msg)
|
raise exception.ParamsError(err_msg)
|
||||||
|
|
||||||
@@ -88,9 +88,9 @@ class ResponseObject(object):
|
|||||||
return top_query_content
|
return top_query_content
|
||||||
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
err_msg = "Failed to extract value from response!\n"
|
err_msg = u"Failed to extract value from response!\n"
|
||||||
err_msg += "response: {}\n".format(self.parsed_dict())
|
err_msg += u"response: {}\n".format(self.parsed_dict())
|
||||||
err_msg += "extract field: {}\n".format(field)
|
err_msg += u"extract field: {}\n".format(field)
|
||||||
logging.error(err_msg)
|
logging.error(err_msg)
|
||||||
raise exception.ParamsError(err_msg)
|
raise exception.ParamsError(err_msg)
|
||||||
|
|
||||||
|
|||||||
@@ -131,11 +131,12 @@ class Runner(object):
|
|||||||
try:
|
try:
|
||||||
resp_obj.validate(validators, self.context.get_testcase_variables_mapping())
|
resp_obj.validate(validators, self.context.get_testcase_variables_mapping())
|
||||||
except (exception.ParamsError, exception.ResponseError, exception.ValidationError):
|
except (exception.ParamsError, exception.ResponseError, exception.ValidationError):
|
||||||
logging.error("Exception occured.")
|
err_msg = u"Exception occured.\n"
|
||||||
logging.error("HTTP request url: \n{}".format(url))
|
err_msg += u"HTTP request url: {}\n".format(url)
|
||||||
logging.error("HTTP request kwargs: \n{}".format(parsed_request))
|
err_msg += u"HTTP request kwargs: \n{}".format(parsed_request)
|
||||||
logging.error("HTTP response status_code: \n{}".format(resp.status_code))
|
err_msg += u"HTTP response status_code: {}\n".format(resp.status_code)
|
||||||
logging.error("HTTP response content: \n{}".format(resp.text))
|
err_msg += u"HTTP response content: \n{}".format(resp.text)
|
||||||
|
logging.error(err_msg)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
setup_teardown(teardown_actions)
|
setup_teardown(teardown_actions)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ def _load_json_file(json_file):
|
|||||||
try:
|
try:
|
||||||
json_content = json.load(data_file)
|
json_content = json.load(data_file)
|
||||||
except exception.JSONDecodeError:
|
except exception.JSONDecodeError:
|
||||||
err_msg = "JSONDecodeError: JSON file format error: {}".format(json_file)
|
err_msg = u"JSONDecodeError: JSON file format error: {}".format(json_file)
|
||||||
logging.error(err_msg)
|
logging.error(err_msg)
|
||||||
raise exception.FileFormatError(err_msg)
|
raise exception.FileFormatError(err_msg)
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ def _load_file(testcase_file_path):
|
|||||||
return _load_yaml_file(testcase_file_path)
|
return _load_yaml_file(testcase_file_path)
|
||||||
else:
|
else:
|
||||||
# '' or other suffix
|
# '' or other suffix
|
||||||
err_msg = "file is not in YAML/JSON format: {}".format(testcase_file_path)
|
err_msg = u"file is not in YAML/JSON format: {}".format(testcase_file_path)
|
||||||
logging.warning(err_msg)
|
logging.warning(err_msg)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ def load_testcases_by_path(path):
|
|||||||
testcases_list = []
|
testcases_list = []
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.error("file not found: {}".format(path))
|
logging.error(u"file not found: {}".format(path))
|
||||||
testcases_list = []
|
testcases_list = []
|
||||||
|
|
||||||
testcases_cache_mapping[path] = testcases_list
|
testcases_cache_mapping[path] = testcases_list
|
||||||
@@ -373,13 +373,13 @@ def check_format(file_path, content):
|
|||||||
"""
|
"""
|
||||||
if not content:
|
if not content:
|
||||||
# testcase file content is empty
|
# testcase file content is empty
|
||||||
err_msg = "Testcase file content is empty: {}".format(file_path)
|
err_msg = u"Testcase file content is empty: {}".format(file_path)
|
||||||
logging.error(err_msg)
|
logging.error(err_msg)
|
||||||
raise exception.FileFormatError(err_msg)
|
raise exception.FileFormatError(err_msg)
|
||||||
|
|
||||||
elif not isinstance(content, (list, dict)):
|
elif not isinstance(content, (list, dict)):
|
||||||
# testcase file content does not match testcase format
|
# testcase file content does not match testcase format
|
||||||
err_msg = "Testcase file content format invalid: {}".format(file_path)
|
err_msg = u"Testcase file content format invalid: {}".format(file_path)
|
||||||
logging.error(err_msg)
|
logging.error(err_msg)
|
||||||
raise exception.FileFormatError(err_msg)
|
raise exception.FileFormatError(err_msg)
|
||||||
|
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ def create_scaffold(project_path):
|
|||||||
|
|
||||||
if os.path.isdir(project_path):
|
if os.path.isdir(project_path):
|
||||||
folder_name = os.path.basename(project_path)
|
folder_name = os.path.basename(project_path)
|
||||||
logging.warning(" Folder {} exists, please specify a new folder name.".format(folder_name))
|
logging.warning(u" Folder {} exists, please specify a new folder name.".format(folder_name))
|
||||||
return
|
return
|
||||||
|
|
||||||
def create_path(path, ptype):
|
def create_path(path, ptype):
|
||||||
|
|||||||
Reference in New Issue
Block a user