Problem updating Locust script to 1.x: TypeError: __init__() takes 1 positional argument but 2 were given

一世执手 提交于 2020-12-13 03:37:28

问题


Having changed (0.x style)

class MyBaseLocust(Locust):
    def __init__(self):
        super(MyLocust, self).__init__()

to (1.x style)

class MyBaseUser(User):
    def __init__(self):
        super(MyBaseUser, self).__init__()

I get:

[2020-07-17 14:16:33,694] XXX/CRITICAL/locust.runners: Unhandled exception in greenlet: <Greenlet at 0x28639396378: <lambda>>
Traceback (most recent call last):
...
 in spawn_users
    hatch()
  File "c:\venv\project\lib\site-packages\locust\runners.py", line 165, in hatch
    new_user = user_class(self.environment)
TypeError: __init__() takes 1 positional argument but 2 were given

(this has been asked a couple of times so I thought I'd add it here)


回答1:


Here’s how it should be in 1.x

class MyBaseUser(HttpUser):
    abstract = True
    def __init__(self, parent):
        super().__init__(parent)

(the main thing is the added parent parameter, but abstract is needed to avoid registering the base user as something that should be executed)



来源:https://stackoverflow.com/questions/62968986/problem-updating-locust-script-to-1-x-typeerror-init-takes-1-positional

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!