locust-初识
# !/usr/bin/env python # -*- coding:utf-8 -*- import os import sys sys.path.append(os.getcwd()) from locust import HttpUser,TaskSet,task, between class Demo(TaskSet): '''例子''' @task(1) def baidu(self): url = '/pytest' header = { "User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" } req = self.client.get(url, headers=header, verify=False) if req.status_code == 200: print("success") else: print("fails") class websitUser(HttpUser): tasks = [Demo] # min_wait = 3000 # max_wait = 6000 wait_time = between(1, 2) host = "http://127.0.0.1:5000"
启动命令:locust -f demo.py
访问web链接:http://localhost:8089/
浙公网安备 33010602011771号