官网:www.locust.io/
产品文档:docs.locust.io/en/2.4.1/
安装
- 配置好pthon、pycharm
- cmd窗口执行:pip3 install locust
- 验证:locust -V
编写python性能接口自动化测试脚本
learn_demo03.py
import json
from json import JSONDecodeError
from locust import task, HttpUser, between
class UserBehavior1(HttpUser):
wait_time = between(2, 5) # 每个用户执行后等待2-5秒
@task # Locust 创建一个 greenlet(微线程),一个微线程可以跑很多协程
def test_login(self):
response = self.client.get("http://localhost:8080/hello")
assert response.status_code == 200
执行: locust -f learn_demo03.py
结果:
参考:https://blog.youkuaiyun.com/m0_70618214/article/details/131307986