Reputation: 2143
I have created a simple load test file for redis, but as I am trying to execute the file as :
locust -f load-test.py
I get an error saying AttributeError: 'NoneType' object has no attribute '_catch_exceptions'
. I cannot understand the reason for this. What is it that I am doing wrong?
Here is the little code, that I wrote.
# Reference
# https://docs.locust.io/en/stable/writing-a-locustfile.html
# https://github.com/andymccurdy/redis-py
from locust import Locust, TaskSet, task
import redis
class LoadTestTasks(TaskSet):
def __init__(self, args):
self.redis = redis.Redis(host='localhost', port=6379)
@task
def update_total_requests(self):
if self.redis.exists("total-calls") == 1:
self.redis.incr("total-calls")
else:
self.redis.set("total-calls", 1)
class Connection(Locust):
task_set = LoadTestTasks
min_wait = 500
max_wait = 700
The stack error:
<Greenlet at 0x109f01ae8: start_locust(<class 'load-test.Connection'>)> failed with AttributeError
[2019-09-20 15:11:26,551] my-PCs-MacBook-Pro.local/ERROR/stderr: Traceback (most recent call last):
[2019-09-20 15:11:26,551] my-PCs-MacBook-Pro.local/ERROR/stderr:
[2019-09-20 15:11:26,551] my-PCs-MacBook-Pro.local/ERROR/stderr: File "/Users/my-pc/anaconda3/lib/python3.7/site-packages/locust/core.py", line 354, in run
if self.locust.stop_timeout is not None and time() - self._time_start > self.locust.stop_timeout:
Upvotes: 1
Views: 2005
Reputation: 459
You have to add super call to __init__
method of TaskSet otherwise your TaskSet is not initialised by Locust.
...
class LoadTestTasks(TaskSet):
def __init__(self, args):
super().__init__(parent)
self.redis = redis.Redis(host='localhost', port=6379)
...
Upvotes: 1