Skip to content

Commit

Permalink
Issue locustio#1832 Display current testscript used
Browse files Browse the repository at this point in the history
  • Loading branch information
tyge68 committed Sep 1, 2021
1 parent ff5e2e5 commit 1a538cb
Show file tree
Hide file tree
Showing 17 changed files with 555 additions and 367 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ docs/_build/**
docs/cli-help-output.txt
docs/config-options.rst
mock.*.egg
web_test_*.csv
.eggs/
dist/**
.idea/**
*.iml
Expand Down
2 changes: 2 additions & 0 deletions locust/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(
user_classes=None,
shape_class=None,
tags=None,
locustfile=None,
exclude_tags=None,
events=None,
host=None,
Expand All @@ -93,6 +94,7 @@ def __init__(
else:
self.events = Events()

self.locustfile = locustfile
self.user_classes = user_classes or []
self.shape_class = shape_class
self.tags = tags
Expand Down
12 changes: 11 additions & 1 deletion locust/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import datetime
from itertools import chain
from .stats import sort_stats
from .user.inspectuser import get_task_ratio_dict
from html import escape
from json import dumps


def render_template(file, **kwargs):
Expand Down Expand Up @@ -42,7 +45,7 @@ def get_html_report(environment, show_download_link=True):
history = stats.history

static_js = []
js_files = ["jquery-1.11.3.min.js", "echarts.common.min.js", "vintage.js", "chart.js"]
js_files = ["jquery-1.11.3.min.js", "echarts.common.min.js", "vintage.js", "chart.js", "tasks.js"]
for js_file in js_files:
path = os.path.join(os.path.dirname(__file__), "static", js_file)
static_js.append("// " + js_file)
Expand All @@ -59,6 +62,11 @@ def get_html_report(environment, show_download_link=True):
static_css.append(f.read())
static_css.extend(["", ""])

task_data = {
"per_class": get_task_ratio_dict(environment.user_classes),
"total": get_task_ratio_dict(environment.user_classes, total=True),
}

res = render_template(
"report.html",
int=int,
Expand All @@ -73,6 +81,8 @@ def get_html_report(environment, show_download_link=True):
static_js="\n".join(static_js),
static_css="\n".join(static_css),
show_download_link=show_download_link,
locustfile=environment.locustfile,
tasks=escape(dumps(task_data)),
)

return res
10 changes: 6 additions & 4 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .shape import LoadTestShape
from .input_events import input_listener
from .html import get_html_report

from json import dumps

version = locust.__version__

Expand Down Expand Up @@ -99,11 +99,12 @@ def load_locustfile(path):
return imported.__doc__, user_classes, shape_class


def create_environment(user_classes, options, events=None, shape_class=None):
def create_environment(user_classes, options, events=None, shape_class=None, locustfile=None):
"""
Create an Environment instance from options
"""
return Environment(
locustfile=locustfile,
user_classes=user_classes,
shape_class=shape_class,
tags=options.tags,
Expand Down Expand Up @@ -204,7 +205,9 @@ def main():
)

# create locust Environment
environment = create_environment(user_classes, options, events=locust.events, shape_class=shape_class)
environment = create_environment(
user_classes, options, events=locust.events, shape_class=shape_class, locustfile=os.path.basename(locustfile)
)

if shape_class and (options.num_users or options.spawn_rate):
logger.warning(
Expand All @@ -220,7 +223,6 @@ def main():
print_task_ratio(user_classes, total=True)
sys.exit(0)
if options.show_task_ratio_json:
from json import dumps

task_data = {
"per_class": get_task_ratio_dict(user_classes),
Expand Down
Loading

0 comments on commit 1a538cb

Please sign in to comment.