locust 2.33.3.dev4__py3-none-any.whl → 2.33.3.dev10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
locust/_version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '2.33.3.dev4'
21
- __version_tuple__ = version_tuple = (2, 33, 3, 'dev4')
20
+ __version__ = version = '2.33.3.dev10'
21
+ __version_tuple__ = version_tuple = (2, 33, 3, 'dev10')
locust/contrib/oai.py ADDED
@@ -0,0 +1,73 @@
1
+ # Note: this User is experimental and may change without notice.
2
+ # The filename is oai.py so it doesnt clash with the openai package.
3
+ from locust.user import User
4
+
5
+ import os
6
+ import time
7
+ from collections.abc import Generator
8
+ from contextlib import contextmanager
9
+
10
+ import httpx
11
+ from openai import OpenAI # dont forget to install openai
12
+
13
+ # convenience for when running in Locust Cloud, where only LOCUST_* env vars are forwarded
14
+ if "LOCUST_OPENAI_API_KEY" in os.environ:
15
+ os.environ["OPENAI_API_KEY"] = os.environ["LOCUST_OPENAI_API_KEY"]
16
+
17
+ if not "OPENAI_API_KEY" in os.environ:
18
+ raise Exception("You need to set OPENAI_API_KEY or LOCUST_OPENAI_API_KEY env var to use OpenAIUser")
19
+
20
+
21
+ class OpenAIClient(OpenAI):
22
+ def __init__(self, request_event, user, *args, **kwargs):
23
+ self.request_name = None # used to override url-based request names
24
+ self.user = user # currently unused, but could be useful later
25
+
26
+ def request_start(request):
27
+ request.start_time = time.time()
28
+ request.start_perf_counter = time.perf_counter()
29
+
30
+ def request_end(response):
31
+ exception = None
32
+ response.read()
33
+ response_time = (time.perf_counter() - response.request.start_perf_counter) * 1000
34
+ try:
35
+ response.raise_for_status()
36
+ except httpx.HTTPStatusError as e:
37
+ exception = e
38
+ request_event.fire(
39
+ request_type=response.request.method,
40
+ name=self.request_name if self.request_name else response.url.path,
41
+ context={},
42
+ response=response,
43
+ exception=exception,
44
+ start_time=response.request.start_time,
45
+ response_time=response_time,
46
+ # Store the number of output tokens as response_length instead of the actual payload size because it is more useful
47
+ response_length=response.json().get("usage", {}).get("output_tokens", 0),
48
+ url=response.url,
49
+ )
50
+
51
+ super().__init__(
52
+ *args,
53
+ **kwargs,
54
+ http_client=httpx.Client(event_hooks={"request": [request_start], "response": [request_end]}),
55
+ )
56
+
57
+ @contextmanager
58
+ def rename_request(self, name: str) -> Generator[None]:
59
+ """Group requests using the "with" keyword"""
60
+
61
+ self.request_name = name
62
+ try:
63
+ yield
64
+ finally:
65
+ self.request_name = None
66
+
67
+
68
+ class OpenAIUser(User):
69
+ abstract = True
70
+
71
+ def __init__(self, *args, **kwargs):
72
+ super().__init__(*args, **kwargs)
73
+ self.client = OpenAIClient(self.environment.events.request, user=self)
locust/web.py CHANGED
@@ -628,7 +628,8 @@ class WebUI:
628
628
  session["auth_info"] = None
629
629
  return login_required(view_func)(*args, **kwargs)
630
630
  except Exception as e:
631
- return f"Locust auth exception: {e} See https://docs.locust.io/en/stable/extending-locust.html#adding-authentication-to-the-web-ui for configuring authentication."
631
+ logger.exception("Locust auth exception")
632
+ return f"Locust auth exception: {e}<br/><br/>See https://docs.locust.io/en/stable/extending-locust.html#adding-authentication-to-the-web-ui for configuring authentication, or disable login by removing --web-login argument."
632
633
  else:
633
634
  return view_func(*args, **kwargs)
634
635
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: locust
3
- Version: 2.33.3.dev4
3
+ Version: 2.33.3.dev10
4
4
  Summary: Developer-friendly load testing framework
5
5
  Project-URL: homepage, https://locust.io/
6
6
  Project-URL: repository, https://github.com/locustio/locust
@@ -1,6 +1,6 @@
1
1
  locust/__init__.py,sha256=aWeuBPUxONjwNm1xp4v8L4BO14SuYLjscIiwJVX1Ui4,1746
2
2
  locust/__main__.py,sha256=vBQ82334kX06ImDbFlPFgiBRiLIinwNk3z8Khs6hd74,31
3
- locust/_version.py,sha256=g_SMblQsWjjmdt6-gdDqNprvpEnrU_GFOIWZnXr2mAQ,526
3
+ locust/_version.py,sha256=UO6ziR9h5tr0Kynlb-ltnmz6DBOmaVFY0Pe0GfIhdoY,528
4
4
  locust/argument_parser.py,sha256=ruSJcY4ouERwVopHvHDK-obQD6nlRKDqjLLwje2SH9k,32806
5
5
  locust/clients.py,sha256=LHAYjaoRjMXwdOB8KBUYRH9-8Uk4F8NvUsDy5UTxKkA,19352
6
6
  locust/debug.py,sha256=7CCm8bIg44uGH2wqBlo1rXBzV2VzwPicLxLewz8r5CQ,5099
@@ -16,10 +16,11 @@ locust/py.typed,sha256=gkWLl8yD4mIZnNYYAIRM8g9VarLvWmTAFeUfEbxJLBw,65
16
16
  locust/runners.py,sha256=62ozCb3S7LetBoOMO1T_L5CuaCpzxqGsjijrV-H71QY,70617
17
17
  locust/shape.py,sha256=t-lwBS8LOjWcKXNL7j2U3zroIXJ1b0fazUwpRYQOKXw,1973
18
18
  locust/stats.py,sha256=soIIvzxOYrEb-CUvLqDgYcoK9XKAX31zE1XkgPWWSQE,46023
19
- locust/web.py,sha256=oVHqJ_vPQ-gLzMZgc8RwqG44DQ6nzbXpta78ihtVCjo,30122
19
+ locust/web.py,sha256=pXAGdixk7gzYLQKRWUbthuapasSrSiF1oCpqIVM14LA,30244
20
20
  locust/contrib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  locust/contrib/fasthttp.py,sha256=lB1t8syshdpJDrNnrN6j00FF4TszdYY8YUfdg-9mwwE,29275
22
22
  locust/contrib/mongodb.py,sha256=1seUYgJOaNKwybYOP9PUEVhgl8hGy-G33f8lFj3R8W8,1246
23
+ locust/contrib/oai.py,sha256=Ot3T8lp31ThckGbNps86oVvq6Vn845Eec0mxhDmONDE,2684
23
24
  locust/contrib/postgres.py,sha256=OuMWnGYN10K65Tq2axVESEW25Y0g5gJb0rK90jkcCJg,1230
24
25
  locust/rpc/__init__.py,sha256=5YOu-58XSnt-oWWNATgXLTNdYoDkkngwHNXprxkWKSM,99
25
26
  locust/rpc/protocol.py,sha256=n-rb3GZQcAlldYDj4E4GuFGylYj_26GSS5U29meft5Y,1282
@@ -50,8 +51,8 @@ locust/webui/dist/assets/graphs-light.png,sha256=7L6pOehXqCojQclzeP91l-LskFQAw_n
50
51
  locust/webui/dist/assets/index-DcS9MJSn.js,sha256=CWbthTyP_6GEGZOqPHZXKAA9r7K0CWX32WWSAHKA9O0,1679855
51
52
  locust/webui/dist/assets/testruns-dark.png,sha256=np6MvpgJ2gkKQ66SOmukLtjsMtHqTSr5dNfza-2XtCo,267621
52
53
  locust/webui/dist/assets/testruns-light.png,sha256=iLAxBZh3kRsfGkcB1-1KSAbFgGji43IqiUrYuJlUoPk,276839
53
- locust-2.33.3.dev4.dist-info/METADATA,sha256=2RZOCl8iSXAR4p5Xdngc-AFjoeY1rSE9mgVS3eHbCFo,9637
54
- locust-2.33.3.dev4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
55
- locust-2.33.3.dev4.dist-info/entry_points.txt,sha256=RAdt8Ku-56m7bFjmdj-MBhbF6h4NX7tVODR9QNnOg0E,44
56
- locust-2.33.3.dev4.dist-info/licenses/LICENSE,sha256=5hnz-Vpj0Z3kSCQl0LzV2hT1TLc4LHcbpBp3Cy-EuyM,1110
57
- locust-2.33.3.dev4.dist-info/RECORD,,
54
+ locust-2.33.3.dev10.dist-info/METADATA,sha256=-P-m-UrjIi5dk6kMHrJOf4JKNZF63goAcFciEMfvVs4,9638
55
+ locust-2.33.3.dev10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
56
+ locust-2.33.3.dev10.dist-info/entry_points.txt,sha256=RAdt8Ku-56m7bFjmdj-MBhbF6h4NX7tVODR9QNnOg0E,44
57
+ locust-2.33.3.dev10.dist-info/licenses/LICENSE,sha256=5hnz-Vpj0Z3kSCQl0LzV2hT1TLc4LHcbpBp3Cy-EuyM,1110
58
+ locust-2.33.3.dev10.dist-info/RECORD,,