gpt4 book ai didi

python - 如何使用多个测试文件运行 locust

转载 作者:行者123 更新时间:2023-12-04 16:38:03 26 4
gpt4 key购买 nike

如何使用多个 locustfiles 运行 locust 测试。 locust 文档对如何执行此操作不是很清楚。

最佳答案

在不同的文件中编写测试。确保每个文件中的类以不同的方式命名。
将所有不同文件中的类导入 locustfile.py (它可以有任何名称,不必是 locustfile.py )
例子。
testfile1.py

from locust import HttpUser, task, between, tag

class WebTests1(HttpUser):
wait_time = between(0,0.1)
def on_start(self):
# on_start is called when a Locust start before any task is scheduled.
pass

def on_stop(self):
# on_stop is called when the TaskSet is stopping
pass


@task(1)
def testaURL1(self):
response = self.client.post("/api/test/url1",
name="test url",
data="some json data",
headers="headers")
testfile2.py
from locust import HttpUser, task, between, tag

class WebTests2(HttpUser):
wait_time = between(0,0.1)
def on_start(self):
# on_start is called when a Locust start before any task is scheduled.
pass

def on_stop(self):
# on_stop is called when the TaskSet is stopping
pass


@task(1)
def testaURL2(2self):
response = self.client.post("/api/test/url2",
name="test url",
data="some json data",
headers="headers")
locustfile.py
 from testfile1 import WebTests1
from testfile2 import WebTests2
将所有文件保存在同一目录中并运行 cmd locustlocust -f locustfile.py它建议您遵循 Python 最佳实践来构建测试代码。引用: https://docs.locust.io/en/stable/writing-a-locustfile.html#how-to-structure-your-test-code

关于python - 如何使用多个测试文件运行 locust,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66771955/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com