Skip to content

Commit

Permalink
--tags: Log a warning if no tasks remain on a User/TaskSet after filt…
Browse files Browse the repository at this point in the history
…ering
  • Loading branch information
cyberw committed Sep 6, 2022
1 parent eb2018c commit 3a7a478
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions locust/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,38 @@ def test_error_when_locustfiles_directory_is_empty(self):
self.assertIn(f"Could not find any locustfiles in directory '{temp_dir}'", stderr)
self.assertEqual(1, proc.returncode)

def test_error_when_no_tasks_match_tags(self):
content = """
from locust import HttpUser, TaskSet, task, constant, LoadTestShape, tag
class MyUser(HttpUser):
host = "http://127.0.0.1:8089"
wait_time = constant(1)
@tag("tag1")
@task
def task1(self):
print("task1")
"""
with mock_locustfile(content=content) as mocked:
proc = subprocess.Popen(
[
"locust",
"-f",
mocked.file_path,
"--headless",
"-t",
"1",
"--tags",
"tag2",
],
stdout=PIPE,
stderr=PIPE,
text=True,
)
stdout, stderr = proc.communicate()
self.assertIn("MyUser had no tasks left after filtering", stderr)
self.assertIn("No tasks defined on MyUser", stderr)
self.assertEqual(1, proc.returncode)


class DistributedIntegrationTests(ProcessIntegrationTest):
def test_expect_workers(self):
Expand Down
2 changes: 2 additions & 0 deletions locust/user/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ def filter_tasks_by_tags(
checked[task] = passing

task_holder.tasks = new_tasks
if not new_tasks:
logging.warning(f"{task_holder.__name__} had no tasks left after filtering, instantiating it will fail!")


class TaskSetMeta(type):
Expand Down

0 comments on commit 3a7a478

Please sign in to comment.