欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

负载性能测试工具之--Locust 安装和类改动问题

程序员文章站 2022-05-18 18:07:46
Locust模块安装在windows+python3环境下安装:使用命令:pip install locustio会报错:报错提醒:Locust packages has removed from ‘locustio’ to 'locust遂改为:pip install locust...

Locust模块安装

1、Locust 安装问题(windows)

在windows+python3(支持3.6、3.7、3.8) 环境下安装:
使用命令:

  • pip install locustio
    会报错:
    负载性能测试工具之--Locust 安装和类改动问题
    报错提醒:
  • **** Locust packages has removed from ‘locustio’ to 'locust……

遂改为:

  • pip install locust
    负载性能测试工具之--Locust 安装和类改动问题

2、Locust中类的名称的变动

如果导入以下类

  • from locust import HttpLocust

    会被告知:

  • ImportError: The HttpLocust class has been renamed to HttpUser in version 1.0.

    所以,应当需要修改为:

  • from locust import HttpUser

3、实例化用户行为类时的问题

from locust import HttpUser, TaskSet, task

# 定义用户行为类
class UserBehavior(TaskSet):
    @task  # 任务项
    def test_login(self):
        user_info = {
            'username':'****',
            'password':'*****'
        }
        url = 'https://smart.mail.163.com/login.htm'
        res = self.client.get(url,data = user_info)
        if res.status_code == 200:
            print('登陆成功!')
        else:
            print('登陆失败!')
            
class WebSiteUser(HttpUser):
    task_set = UserBehavior
    max_wait = 5000
    min_wait = 1000

你运行,系统会告诉你:

  • DeprecationWarning: Usage of User.task_set is deprecated since version 1.0. Set the tasks attribute instead (tasks = [UserBehavior]) "(tasks = [%s])" % task_set.__name__, DeprecationWarning)

    注意:此处的 - task_set = UserBehavior

    版本1.0开始,就不支持使用 task_set进行实例化,可能是和内部的一些重名了吧……

    所以要改一下,比如 - task_create = UserBehavior等等能成功运行的……

更多的参考:Locust说明文档

本文地址:https://blog.csdn.net/weixin_42422090/article/details/107482113

相关标签: python自动化测试