locust 0.9 to 1.3 Exception: No tasks defined. use the @task decorator or set the tasks property of the User

5.7k Views Asked by At

I have the following code which run fine in locust 0.9. Now with 1.3 it throws the exception mentioned in the title. Can anyone see what's wrong?

import time
import random
import datetime
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import logging
import json
import os
from random import randint, choice

from locust import HttpUser, TaskSet, task
from pyquery import PyQuery

requests.packages.urllib3.disable_warnings()

class FrontPage(TaskSet):
    def on_start(self):
        self.client.verify = False

    @task(20)
    def index(self):
        self.client.get("/")
    
class DestinationPagesFixed(TaskSet):
    de_paths = ["/belgien", "daenemark", "deutschland", "frankreich", "griechenland"
    , "italien"
    , "luxemburg"
    ]
    def on_start(self):
        self.client.verify = False
    @task
    def test_1(self):
        paths = self.de_paths
        path = choice(paths)
        self.client.get(path, name="Static page")

class UserBehavior(TaskSet):
    tasks = {FrontPage: 15, DestinationPagesFixed: 19}


class WebsiteUser(HttpUser):
    task_set = UserBehavior
    min_wait = 400
    max_wait = 10000
1

There are 1 best solutions below

0
On

Change

task_set = UserBehavior

to

tasks = [UserBehavior]

Or (skipping your UserBehaviour class entirely)

tasks = {FrontPage: 15, DestinationPagesFixed: 19}