我正在尝试在Hocust中运行测试,但遇到以下异常:
Python: __init__() missing 1 required positional argument: 'ecu_model_id'.
我正在编写针对其他测试的测试,他们在构造函数中没有更多内容。你知道这段代码有什么问题吗? 如果你还需要什么,请告诉我
from locust import task, HttpUser
from apicall.ecu import EcuModelApi
from common.configuration import config
ECU_TO_CREATE_1K = 1000
ECU_NAME = config['vehicle']['ecuModel']
global_counter = 0
lock = threading.Lock()
class Add1KECUs(HttpUser):
def on_start(self):
super().on_start()
self.ecu_model_id = EcuModelApi(self.client).get_ecu_model_id_by_name(ECU_NAME)
self.ecu_api = EcuModelApi(self.client, self.ecu_model_id)
回溯:
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
File "/home/bgryczka/pythonEnvironment/lib/python3.8/site-packages/locust/user/users.py", line 166, in run_user
user.run()
File "/home/bgryczka/pythonEnvironment/lib/python3.8/site-packages/locust/user/users.py", line 132, in run
self.on_start()
File "/home/bgryczka/dev/sources/locust-swm-performance-tests/tests/add1KECUs.py", line 19, in on_start
self.ecu_model_id = EcuModelApi(self.client).get_ecu_model_id_by_name(ECU_NAME)
TypeError: __init__() missing 1 required positional argument: 'ecu_model_id'
2021-09-15T11:09:55Z <Greenlet at 0x7f4351a65e10: run_user(<add1KECUs.Add1KECUs object at 0x7f4351193070>)> failed with TypeError
在
class Add1KECUs(HttpUser):
中,在开头添加一个函数,如下所示:因此,您的
class
现在将为:然后是函数的其余代码
现在,在代码中使用HttpUser的地方,将其更改为
self.user
(在__init__
函数中除外)现在以以下方式运行您的类:
相关问题 更多 >
编程相关推荐