locust 2.32.6.dev10__py3-none-any.whl → 2.32.6.dev14__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
@@ -14,7 +14,7 @@ __version_tuple__: VERSION_TUPLE
14
14
  version_tuple: VERSION_TUPLE
15
15
 
16
16
 
17
- __version__ = "2.32.6.dev10"
17
+ __version__ = "2.32.6.dev14"
18
18
  version = __version__
19
- __version_tuple__ = (2, 32, 6, "dev10")
19
+ __version_tuple__ = (2, 32, 6, "dev14")
20
20
  version_tuple = __version_tuple__
locust/argument_parser.py CHANGED
@@ -6,6 +6,7 @@ from locust.rpc import Message, zmqrpc
6
6
 
7
7
  import ast
8
8
  import atexit
9
+ import json
9
10
  import os
10
11
  import platform
11
12
  import socket
@@ -28,6 +29,7 @@ import gevent
28
29
  import requests
29
30
 
30
31
  from .util.directory import get_abspaths_in
32
+ from .util.timespan import parse_timespan
31
33
  from .util.url import is_url
32
34
 
33
35
  version = locust.__version__
@@ -369,6 +371,66 @@ def parse_locustfile_option(args=None) -> list[str]:
369
371
  return parsed_paths
370
372
 
371
373
 
374
+ # A hack for setting up an action that raises ArgumentError with configurable error messages.
375
+ # This is meant to be used to immediately block use of deprecated arguments with some helpful messaging.
376
+
377
+
378
+ def raise_argument_type_error(err_msg):
379
+ class ErrorRaisingAction(configargparse.Action):
380
+ def __call__(self, parser, namespace, values, option_string=None):
381
+ raise configargparse.ArgumentError(self, err_msg)
382
+
383
+ return ErrorRaisingAction
384
+
385
+
386
+ # Definitions for some "types" to use with the arguments
387
+
388
+
389
+ def timespan(time_str) -> int:
390
+ try:
391
+ return parse_timespan(time_str)
392
+ except ValueError as e:
393
+ raise configargparse.ArgumentTypeError(str(e))
394
+
395
+
396
+ def positive_integer(string) -> int:
397
+ try:
398
+ value = int(string)
399
+ except ValueError:
400
+ raise configargparse.ArgumentTypeError(f"invalid int value: '{string}'")
401
+
402
+ if value < 1:
403
+ raise configargparse.ArgumentTypeError(
404
+ f"Invalid --expect-workers argument ({value}), must be a positive number"
405
+ )
406
+
407
+ return value
408
+
409
+
410
+ def json_user_config(string):
411
+ try:
412
+ if string.endswith(".json"):
413
+ with open(string) as file:
414
+ user_config = json.load(file)
415
+ else:
416
+ user_config = json.loads(string)
417
+
418
+ if not isinstance(user_config, list):
419
+ user_config = [user_config]
420
+
421
+ for config in user_config:
422
+ if "user_class_name" not in config:
423
+ raise configargparse.ArgumentTypeError("The user config must specify a user_class_name")
424
+
425
+ return user_config
426
+
427
+ except json.decoder.JSONDecodeError as e:
428
+ raise configargparse.ArgumentTypeError(f"The --config-users argument must be a valid JSON string or file: {e}")
429
+
430
+ except FileNotFoundError as e:
431
+ raise configargparse.ArgumentTypeError(str(e))
432
+
433
+
372
434
  def setup_parser_arguments(parser):
373
435
  """
374
436
  Setup command-line options
@@ -401,20 +463,13 @@ def setup_parser_arguments(parser):
401
463
  help="Rate to spawn users at (users per second). Primarily used together with --headless or --autostart",
402
464
  env_var="LOCUST_SPAWN_RATE",
403
465
  )
404
- parser.add_argument(
405
- "--hatch-rate",
406
- env_var="LOCUST_HATCH_RATE",
407
- metavar="<float>",
408
- type=float,
409
- default=0,
410
- help=configargparse.SUPPRESS,
411
- )
412
466
  parser.add_argument(
413
467
  "-t",
414
468
  "--run-time",
415
469
  metavar="<time string>",
416
470
  help="Stop after the specified amount of time, e.g. (300s, 20m, 3h, 1h30m, etc.). Only used together with --headless or --autostart. Defaults to run forever.",
417
471
  env_var="LOCUST_RUN_TIME",
472
+ type=timespan,
418
473
  )
419
474
  parser.add_argument(
420
475
  "-l",
@@ -425,7 +480,7 @@ def setup_parser_arguments(parser):
425
480
  )
426
481
  parser.add_argument(
427
482
  "--config-users",
428
- type=str,
483
+ type=json_user_config,
429
484
  nargs="*",
430
485
  help="User configuration as a JSON string or file. A list of arguments or an Array of JSON configuration may be provided",
431
486
  env_var="LOCUST_CONFIG_USERS",
@@ -489,6 +544,9 @@ def setup_parser_arguments(parser):
489
544
  default=None,
490
545
  help=configargparse.SUPPRESS,
491
546
  env_var="LOCUST_WEB_AUTH",
547
+ action=raise_argument_type_error(
548
+ "The --web-auth parameters has been replaced with --web-login. See https://docs.locust.io/en/stable/extending-locust.html#authentication for details"
549
+ ),
492
550
  )
493
551
  web_ui_group.add_argument(
494
552
  "--web-login",
@@ -528,7 +586,8 @@ def setup_parser_arguments(parser):
528
586
  web_ui_group.add_argument(
529
587
  "--legacy-ui",
530
588
  default=False,
531
- action="store_true",
589
+ action=raise_argument_type_error("--legacy-ui is no longer supported, remove the parameter to continue"),
590
+ nargs=0,
532
591
  help=configargparse.SUPPRESS,
533
592
  env_var="LOCUST_LEGACY_UI",
534
593
  )
@@ -561,7 +620,7 @@ def setup_parser_arguments(parser):
561
620
  )
562
621
  master_group.add_argument(
563
622
  "--expect-workers",
564
- type=int,
623
+ type=positive_integer,
565
624
  metavar="<int>",
566
625
  default=1,
567
626
  help="Delay starting the test until this number of workers have connected (only used in combination with --headless/--autostart).",
@@ -584,7 +643,8 @@ def setup_parser_arguments(parser):
584
643
  )
585
644
  master_group.add_argument(
586
645
  "--expect-slaves",
587
- action="store_true",
646
+ action=raise_argument_type_error("The --expect-slaves parameter has been renamed --expect-workers"),
647
+ nargs=0,
588
648
  help=configargparse.SUPPRESS,
589
649
  )
590
650
 
@@ -608,7 +668,8 @@ Typically ONLY these options (and --locustfile) need to be specified on workers,
608
668
  )
609
669
  worker_group.add_argument(
610
670
  "--slave",
611
- action="store_true",
671
+ action=raise_argument_type_error("The --slave parameter has been renamed --worker"),
672
+ nargs=0,
612
673
  help=configargparse.SUPPRESS,
613
674
  )
614
675
  worker_group.add_argument(
@@ -720,6 +781,8 @@ Typically ONLY these options (and --locustfile) need to be specified on workers,
720
781
  help="Choose between DEBUG/INFO/WARNING/ERROR/CRITICAL. Default is INFO.",
721
782
  metavar="<level>",
722
783
  env_var="LOCUST_LOGLEVEL",
784
+ choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
785
+ type=str.upper,
723
786
  )
724
787
  log_group.add_argument(
725
788
  "--logfile",
@@ -764,6 +827,7 @@ Typically ONLY these options (and --locustfile) need to be specified on workers,
764
827
  default="0",
765
828
  help="Number of seconds to wait for a simulated user to complete any executing task before exiting. Default is to terminate immediately. When running distributed, this only needs to be specified on the master.",
766
829
  env_var="LOCUST_STOP_TIMEOUT",
830
+ type=timespan,
767
831
  )
768
832
  other_group.add_argument(
769
833
  "--equal-weights",
locust/main.py CHANGED
@@ -7,6 +7,7 @@ import errno
7
7
  import gc
8
8
  import importlib.metadata
9
9
  import inspect
10
+ import itertools
10
11
  import json
11
12
  import logging
12
13
  import os
@@ -35,7 +36,6 @@ from .stats import (
35
36
  )
36
37
  from .user.inspectuser import print_task_ratio, print_task_ratio_json
37
38
  from .util.load_locustfile import load_locustfile
38
- from .util.timespan import parse_timespan
39
39
 
40
40
  # import external plugins if installed to allow for registering custom arguments etc
41
41
  try:
@@ -172,35 +172,13 @@ def main():
172
172
  if options.headful:
173
173
  options.headless = False
174
174
 
175
- if options.slave or options.expect_slaves:
176
- sys.stderr.write("The --slave/--expect-slaves parameters have been renamed --worker/--expect-workers\n")
177
- sys.exit(1)
178
-
179
- if options.web_auth:
180
- sys.stderr.write(
181
- "The --web-auth parameters has been replaced with --web-login. See https://docs.locust.io/en/stable/extending-locust.html#authentication for details\n"
182
- )
183
- sys.exit(1)
184
-
185
175
  if options.autoquit != -1 and not options.autostart:
186
176
  sys.stderr.write("--autoquit is only meaningful in combination with --autostart\n")
187
177
  sys.exit(1)
188
178
 
189
- if options.hatch_rate:
190
- sys.stderr.write("--hatch-rate parameter has been renamed --spawn-rate\n")
191
- sys.exit(1)
192
-
193
- if options.legacy_ui:
194
- sys.stderr.write("--legacy-ui is no longer supported, remove the parameter to continue\n")
195
- sys.exit(1)
196
-
197
179
  # setup logging
198
180
  if not options.skip_log_setup:
199
- if options.loglevel.upper() in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]:
200
- setup_logging(options.loglevel, options.logfile)
201
- else:
202
- sys.stderr.write("Invalid --loglevel. Valid values are: DEBUG/INFO/WARNING/ERROR/CRITICAL\n")
203
- sys.exit(1)
181
+ setup_logging(options.loglevel, options.logfile)
204
182
 
205
183
  children = []
206
184
  logger = logging.getLogger(__name__)
@@ -312,13 +290,6 @@ def main():
312
290
  if sys.version_info < (3, 10):
313
291
  logger.warning("Python 3.9 support is deprecated and will be removed soon")
314
292
 
315
- if options.stop_timeout:
316
- try:
317
- options.stop_timeout = parse_timespan(options.stop_timeout)
318
- except ValueError:
319
- logger.error("Valid --stop-timeout formats are: 20, 20s, 3m, 2h, 1h20m, 3h30m10s, etc.")
320
- sys.exit(1)
321
-
322
293
  if options.list_commands:
323
294
  print("Available Users:")
324
295
  for name in user_classes:
@@ -382,39 +353,17 @@ See https://github.com/locustio/locust/wiki/Installation#increasing-maximum-numb
382
353
  )
383
354
 
384
355
  if options.config_users:
385
- for json_user_config in options.config_users:
386
- try:
387
- if json_user_config.endswith(".json"):
388
- with open(json_user_config) as file:
389
- user_config = json.load(file)
390
- else:
391
- user_config = json.loads(json_user_config)
392
-
393
- def ensure_user_class_name(config):
394
- if "user_class_name" not in config:
395
- logger.error("The user config must specify a user_class_name")
396
- sys.exit(-1)
397
-
398
- if isinstance(user_config, list):
399
- for config in user_config:
400
- ensure_user_class_name(config)
401
-
402
- environment.update_user_class(config)
403
- else:
404
- ensure_user_class_name(user_config)
405
-
406
- environment.update_user_class(user_config)
407
- except json.decoder.JSONDecodeError as e:
408
- logger.error(f"The --config-users argument must be in valid JSON string or file: {e}")
409
- sys.exit(-1)
410
- except KeyError as e:
411
- logger.error(
412
- f"Error applying user config, probably you tried to specify config for a User not present in your locustfile: {e}"
413
- )
414
- sys.exit(-1)
415
- except Exception as e:
416
- logger.exception(e)
417
- sys.exit(-1)
356
+ try:
357
+ for user_config in itertools.chain(*options.config_users):
358
+ environment.update_user_class(user_config)
359
+ except KeyError as e:
360
+ logger.error(
361
+ f"Error applying user config, probably you tried to specify config for a User not present in your locustfile: {e}"
362
+ )
363
+ sys.exit(-1)
364
+ except Exception as e:
365
+ logger.exception(e)
366
+ sys.exit(-1)
418
367
 
419
368
  if (
420
369
  shape_class
@@ -469,13 +418,6 @@ See https://github.com/locustio/locust/wiki/Installation#increasing-maximum-numb
469
418
  if options.run_time:
470
419
  if options.worker:
471
420
  logger.info("--run-time specified for a worker node will be ignored.")
472
- try:
473
- options.run_time = parse_timespan(options.run_time)
474
- except ValueError:
475
- logger.error(
476
- f"Invalid --run-time argument ({options.run_time}), accepted formats are for example 120, 120s, 2m, 3h, 3h30m10s."
477
- )
478
- sys.exit(1)
479
421
 
480
422
  if options.csv_prefix:
481
423
  base_csv_file = os.path.basename(options.csv_prefix)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: locust
3
- Version: 2.32.6.dev10
3
+ Version: 2.32.6.dev14
4
4
  Summary: Developer-friendly load testing framework
5
5
  Home-page: https://locust.io/
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
1
  locust/__init__.py,sha256=Jit8eNUrwuMLqavyFvMZr69e61DILq_KB4yT4MciScw,1681
2
2
  locust/__main__.py,sha256=vBQ82334kX06ImDbFlPFgiBRiLIinwNk3z8Khs6hd74,31
3
- locust/_version.py,sha256=zvPotUZDJqMUAHdnDbenmqF2raNAvLGh85JXtL3gRM8,460
4
- locust/argument_parser.py,sha256=xB9TQhAALeIZLx0hxoBOVv4dhSNdB15BG0fDYXkyeFc,30137
3
+ locust/_version.py,sha256=X1PvdUAPDrBMpS2DWr-cM7-_WvCLFKVGN5HLKpZOtcA,460
4
+ locust/argument_parser.py,sha256=NsTd3R_7BCLyXsaHi_1ld40GMOVxJ6a3Ju2kyvHGy6o,32486
5
5
  locust/clients.py,sha256=XK-xabq2_5GZKMEjebDobvEjeBTtCs8h2EelL7s68Qs,19346
6
6
  locust/contrib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  locust/contrib/fasthttp.py,sha256=ehnOrIe1U6C0gW8fRoyHv7-HSSHxfEJxKb5zHw-y1aU,28758
@@ -15,7 +15,7 @@ locust/exception.py,sha256=jGgJ32ubuf4pWdlaVOkbh2Y0LlG0_DHi-lv3ib8ppOE,1791
15
15
  locust/html.py,sha256=X9N8u42aHptcQdRZ5cLrBmDuXqRW0yXH_TaWPsWfweY,3691
16
16
  locust/input_events.py,sha256=ZIyePyAMuA_YFYWg18g_pE4kwuQV3RbEB250MzXRwjY,3314
17
17
  locust/log.py,sha256=5E2ZUOa3V4sfCqa-470Gle1Ik9L5nxYitsjEB9tRwE0,3455
18
- locust/main.py,sha256=8U2zaGQWvqZMufGd2eny2q8WpSaZFHUEJTqhNNRXF80,30434
18
+ locust/main.py,sha256=O-mHV12OLcufPjJiGMLL-OPK3-SYvuMEPlssF_JHrb8,27913
19
19
  locust/py.typed,sha256=gkWLl8yD4mIZnNYYAIRM8g9VarLvWmTAFeUfEbxJLBw,65
20
20
  locust/rpc/__init__.py,sha256=nVGoHWFQxZjnhCDWjbgXIbmFbN9sizAjkhvSs9_642c,58
21
21
  locust/rpc/protocol.py,sha256=n-rb3GZQcAlldYDj4E4GuFGylYj_26GSS5U29meft5Y,1282
@@ -47,8 +47,8 @@ locust/webui/dist/auth.html,sha256=JYZcdglsfY3B4LEPCteWiNd5kPX21Lx1oaaI00iCTxo,6
47
47
  locust/webui/dist/index.html,sha256=uMAhFNZjFQrWASkqHYx0GPsGSs2DO00OrRkvWItpv38,654
48
48
  locust/webui/dist/report.html,sha256=wd_TO5cREIfgk0ru49DX0Zlxopb5iWsyuB36v_rfST8,1474524
49
49
  poetry.lock,sha256=a4ZAnX6LNBWBJnqtxt4gK0uPSqPsBdDitylFj1rL3LA,214415
50
- locust-2.32.6.dev10.dist-info/LICENSE,sha256=5hnz-Vpj0Z3kSCQl0LzV2hT1TLc4LHcbpBp3Cy-EuyM,1110
51
- locust-2.32.6.dev10.dist-info/METADATA,sha256=9AzRe-3-9DK_D_QqwTYcyVYm4wZZhKYeMUkKai7Bmfc,9991
52
- locust-2.32.6.dev10.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
53
- locust-2.32.6.dev10.dist-info/entry_points.txt,sha256=RhIxlLwU_Ae_WjimS5COUDLagdCh6IOMyLtgaQxNmlM,43
54
- locust-2.32.6.dev10.dist-info/RECORD,,
50
+ locust-2.32.6.dev14.dist-info/LICENSE,sha256=5hnz-Vpj0Z3kSCQl0LzV2hT1TLc4LHcbpBp3Cy-EuyM,1110
51
+ locust-2.32.6.dev14.dist-info/METADATA,sha256=x76twu79Sr3C5uUUABKXHgoMKgAv6zaC9mjHyLVXJno,9991
52
+ locust-2.32.6.dev14.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
53
+ locust-2.32.6.dev14.dist-info/entry_points.txt,sha256=RhIxlLwU_Ae_WjimS5COUDLagdCh6IOMyLtgaQxNmlM,43
54
+ locust-2.32.6.dev14.dist-info/RECORD,,