python - 如何为动态 URL 列表创建 Locust 任务?

标签 python python-3.x python-3.6 locust

我正在尝试获取基于 OpenAPI JSON 的所有我的 API 端点的计时信息,因此我想在 setup 方法中执行类似的操作:

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]

或者有其他方法在运行时生成任务吗?

最佳答案

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()

关于python - 如何为动态 URL 列表创建 Locust 任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54450832/

相关文章:

python - 从列表中以相反的顺序删除短语

Python:在两个字符之间拆分

python - 为什么 Pandas/Numpy 自动将 9999999999 向上舍入为 1.000000e+10?

compiler-errors - 如何克服python的编译(Nuitka)错误

python - 在 python 中结合 with 语句和 for 循环

python - 你如何修复 "Missing module docstringpylint(missing-module-docstring)"

python - 试图在两个字符串中找到匹配项 - Python

python-3.6 - 系列对象没有属性 'order'

Python:如何跨多个类封装一个变量?

python - 如何使用Python从嵌套字典中提取唯一值?