【发布时间】:2021-06-15 10:06:40
【问题描述】:
我正在尝试使用 pytest 运行 locust。我已经创建了这个 python 文件,但它没有显示任何输出。 pytest 不收集测试。如何在 pytest 中使用 locust
from locust import HttpUser, TaskSet, task
class WebsiteTasks(TaskSet):
def on_start(self):
self.index()
@task(2)
def index(self):
self.client.get("/")
@task(1)
def about(self):
self.client.get("/page/about")
class WebsiteUser(HttpUser):
task = WebsiteTasks
host = "localhost:5000"
min_wait = 1000
max_wait = 5000
当我运行 pytest locust_test.py 这是输出:
================================================================ test session starts ================================================================
platform linux -- Python 3.8.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /home/user/Desktop/testing
collected 0 items
【问题讨论】:
-
如果您想使用 pytest 驱动 locust 负载测试,我的建议是根本不要这样做。 pytest 用于短期测试。蝗虫用于负载测试。他们不会在一起玩得很好。
标签: python python-3.x testing pytest locust