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

run_single_user improvements #2519

Merged
merged 5 commits into from
Dec 19, 2023
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
10 changes: 7 additions & 3 deletions locust/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import inspect
import locust
import locust.log
from locust import User, argument_parser
from typing import Type, Optional
from locust.env import Environment
Expand Down Expand Up @@ -102,7 +103,7 @@ def run_single_user(
include_time=False,
include_context=False,
include_payload=False,
loglevel=None,
loglevel: Optional[str] = "WARNING",
):
"""
Runs a single User. Useful when you want to run a debugger.
Expand All @@ -113,8 +114,8 @@ def run_single_user(

It prints some info about every request to stdout, and you can get additional info using the `include_*` flags

By default, it does not set up locusts logging system (because it could interfere with the printing of requests),
but you can change that by passing a log level (e.g. *loglevel="INFO"*)
It also initiates logging on WARNING level (not INFO, because it could interfere with the printing of requests),
but you can change that by passing a log level (or disabling logging entirely by passing None)
"""
global _env

Expand All @@ -141,6 +142,9 @@ def run_single_user(
)
# fire various events (quit and test_stop will never get called, sorry about that)
_env.events.init.fire(environment=_env, runner=None, web_ui=None)
# uncaught events will be suppressed, so check if that happened
if locust.log.unhandled_greenlet_exception:
raise Exception("Unhandled exception in init")

# do the things that the Runner usually does
_env.user_classes = [user_class]
Expand Down
7 changes: 5 additions & 2 deletions locust/test/test_debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_run_single_user_pass_host_to_user_classes(self):

class MyUser1(HttpUser):
@task
def my_task():
def my_task(self):
pass

def _stop_user():
Expand All @@ -34,4 +34,7 @@ def _stop_user():
t = Timer(1, _stop_user)
t.start()

debug.run_single_user(MyUser1)
debug.run_single_user(
MyUser1,
loglevel=None, # another log setup might mess with other tests...
)
2 changes: 1 addition & 1 deletion locust/user/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def decorator_func(func):
Check if task was used without parentheses (not called), like this::

@task
def my_task()
def my_task(self)
pass
"""
if callable(weight):
Expand Down
Loading