mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +08:00
locusts: report exception when error occured
This commit is contained in:
@@ -1 +1 @@
|
|||||||
__version__ = '0.7.7'
|
__version__ = '0.7.8'
|
||||||
@@ -1,18 +1,16 @@
|
|||||||
#coding: utf-8
|
#coding: utf-8
|
||||||
import zmq
|
import zmq
|
||||||
from locust import HttpLocust, TaskSet, task
|
from locust import HttpLocust, TaskSet, task
|
||||||
from ate import runner, exception
|
from locust.events import request_failure
|
||||||
|
from ate import runner
|
||||||
|
|
||||||
class WebPageTasks(TaskSet):
|
class WebPageTasks(TaskSet):
|
||||||
def on_start(self):
|
def on_start(self):
|
||||||
self.test_runner = runner.Runner(self.client)
|
self.test_runner = runner.Runner(self.client, request_failure)
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def test_specified_scenario(self):
|
def test_specified_scenario(self):
|
||||||
try:
|
self.test_runner.run(self.locust.file_path)
|
||||||
self.test_runner.run(self.locust.file_path)
|
|
||||||
except exception.ValidationError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
class WebPageUser(HttpLocust):
|
class WebPageUser(HttpLocust):
|
||||||
host = "$HOST"
|
host = "$HOST"
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ from ate.context import Context
|
|||||||
|
|
||||||
class Runner(object):
|
class Runner(object):
|
||||||
|
|
||||||
def __init__(self, http_client_session=None):
|
def __init__(self, http_client_session=None, request_failure_hook=None):
|
||||||
self.http_client_session = http_client_session
|
self.http_client_session = http_client_session
|
||||||
self.context = Context()
|
self.context = Context()
|
||||||
testcase.load_test_dependencies()
|
testcase.load_test_dependencies()
|
||||||
|
self.request_failure_hook = request_failure_hook
|
||||||
|
|
||||||
def init_config(self, config_dict, level):
|
def init_config(self, config_dict, level):
|
||||||
""" create/update context variables binds
|
""" create/update context variables binds
|
||||||
@@ -131,7 +132,9 @@ class Runner(object):
|
|||||||
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.")
|
logging.error("Exception occured.")
|
||||||
|
logging.error("HTTP request url: \n{}".format(url))
|
||||||
logging.error("HTTP request kwargs: \n{}".format(parsed_request))
|
logging.error("HTTP request kwargs: \n{}".format(parsed_request))
|
||||||
|
logging.error("HTTP response status_code: \n{}".format(resp.status_code))
|
||||||
logging.error("HTTP response content: \n{}".format(resp.text))
|
logging.error("HTTP response content: \n{}".format(resp.text))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@@ -155,9 +158,9 @@ class Runner(object):
|
|||||||
"testcases": [
|
"testcases": [
|
||||||
{
|
{
|
||||||
"name": "testcase description",
|
"name": "testcase description",
|
||||||
"variables": [], # optional, override
|
"variables": [], # optional, override
|
||||||
"request": {},
|
"request": {},
|
||||||
"extract": {}, # optional
|
"extract": {}, # optional
|
||||||
"validate": {} # optional
|
"validate": {} # optional
|
||||||
},
|
},
|
||||||
testcase12
|
testcase12
|
||||||
@@ -183,9 +186,17 @@ class Runner(object):
|
|||||||
testcases = testset.get("testcases", [])
|
testcases = testset.get("testcases", [])
|
||||||
for testcase_dict in testcases:
|
for testcase_dict in testcases:
|
||||||
try:
|
try:
|
||||||
assert self._run_test(testcase_dict)
|
self._run_test(testcase_dict)
|
||||||
except AssertionError:
|
except exception.MyBaseError as ex:
|
||||||
success = False
|
success = False
|
||||||
|
if self.request_failure_hook:
|
||||||
|
self.request_failure_hook.fire(
|
||||||
|
request_type=testcase_dict.get("request", {}).get("method"),
|
||||||
|
name=testcase_dict.get("request", {}).get("url"),
|
||||||
|
response_time=0,
|
||||||
|
exception=ex
|
||||||
|
)
|
||||||
|
break
|
||||||
|
|
||||||
output_variables_list = config_dict.get("output", [])
|
output_variables_list = config_dict.get("output", [])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user