【发布时间】:2020-08-31 00:02:54
【问题描述】:
我之前曾询问并解决了使用旧版本的locust转储stats的问题,但是在locust 1.0.0中删除了setup和teardown方法,现在我无法获取主机(基本网址)。
我希望在请求运行后打印出一些有关请求的信息。按照https://docs.locust.io/en/stable/extending-locust.html 的文档,我在我的顺序任务集中有一个request_success 侦听器 - 下面是一些粗略的示例代码:
class SearchSequentialTest(SequentialTaskSet):
@task
def search(self):
path = '/search/tomatoes'
headers = {"Content-Type": "application/json",
unique_identifier = uuid.uuid4()
data = {
"name": f"Performance-{unique_identifier}",
}
with self.client.post(
path,
data=json.dumps(data),
headers=headers,
catch_response=True,
) as response:
json_response = json.loads(response.text)
self.items = json_response['result']['payload'][0]['uuid']
print(json_response)
@events.request_success.add_listener
def my_success_handler(request_type, name, response_time, response_length, **kw):
print(f"Successfully made a request to: {self.host}/{name}")
但我无法访问 self.host - 如果我删除它,我只会得到一个相对 URL。
如何访问 TaskSet 的事件挂钩中的 base_url?
【问题讨论】:
标签: python-3.x performance-testing locust