locust_单接口
from locust import HttpLocust, TaskSet, task import os #利用@seq_task可以较为快速的定义执行的先后顺序 class BlogDemo(TaskSet): def on_start(self): print("性能测试开始") #用户行为:打开我的博客首页demo @task(1) def open_blog(self): # 定义requests的请求头 header = {"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36"} r = self.client.get("/wangwangdezhou", headers=header, verify=False) print(r.status_code) assert r.status_code == 200 #性能配置 class websitUser(HttpLocust): task_set = BlogDemo min_wait = 3000 # 单位毫秒 max_wait = 6000 # 单位毫秒 if __name__ == "__main__": os.system("locust -f 登陆首页压测.py --host=https://www.cnblogs.com")
心之所向无人可挡