问题
I'm trying to get timing information for all my API endpoints based on the OpenAPI JSON, so I would like to do something like this in the setup
method:
for api_path in self.client.get('/api/doc/?format=openapi').json()['paths'].keys():
self.get_[api_path] = [@task decorated method which retrieves the API path]
Or is there another way to generate tasks at runtime?
回答1:
Found it in the API docs:
def setup(self) -> None:
for api_path in self.client.get('/api/doc/?format=openapi').json()['paths'].keys():
self.schedule_task(self.api_task, args=[api_path])
def api_task(self, path: str) -> None:
response = self.client.get("/api{}?limit=1000".format(path))
assert response.status_code == HTTPStatus.OK, response.content.decode()
来源:https://stackoverflow.com/questions/54450832/how-to-create-a-locust-task-for-a-dynamic-list-of-urls