Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give a more descriptive error when the Locust or TaskSet has no tasks. #1287

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions locust/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ def schedule_task(self, task_callable, args=None, kwargs=None, first=False):
self._task_queue.append(task)

def get_next_task(self):
if not self.tasks:
raise Exception("No tasks defined. use the @task decorator or set the tasks property of the TaskSet")
return random.choice(self.tasks)

def wait_time(self):
Expand Down
15 changes: 15 additions & 0 deletions locust/test/test_locust_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ class MyTasks(TaskSet):
self.assertEqual(t1_count, 5)
self.assertEqual(t2_count, 2)

def test_tasks_missing_gives_user_friendly_exception(self):
class User(Locust):
wait_time = constant(0)
tasks = None
_catch_exceptions = False

class MyTasks(TaskSet):
tasks = None

l = MyTasks(User(self.environment))
self.assertRaisesRegex(Exception, "No tasks defined.*", l.run)
l.tasks = None
self.assertRaisesRegex(Exception, "No tasks defined.*", l.run)

def test_task_decorator_ratio(self):
t1 = lambda l: None
t2 = lambda l: None
Expand Down Expand Up @@ -178,6 +192,7 @@ def t1(self):
taskset = MyTaskSet3(self.locust)
self.assertEqual(len(taskset.tasks), 3)


def test_wait_function(self):
class MyTaskSet(TaskSet):
a = 1
Expand Down