robotframework-locust 1.0.1__tar.gz

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.
Files changed (88) hide show
  1. robotframework_locust-1.0.1/LICENSE +21 -0
  2. robotframework_locust-1.0.1/PKG-INFO +178 -0
  3. robotframework_locust-1.0.1/README.md +142 -0
  4. robotframework_locust-1.0.1/pyproject.toml +103 -0
  5. robotframework_locust-1.0.1/setup.cfg +4 -0
  6. robotframework_locust-1.0.1/src/LocustLibrary/__init__.py +143 -0
  7. robotframework_locust-1.0.1/src/LocustLibrary/builder.py +169 -0
  8. robotframework_locust-1.0.1/src/LocustLibrary/calllog.py +115 -0
  9. robotframework_locust-1.0.1/src/LocustLibrary/checks.py +122 -0
  10. robotframework_locust-1.0.1/src/LocustLibrary/distributed.py +52 -0
  11. robotframework_locust-1.0.1/src/LocustLibrary/feed.py +61 -0
  12. robotframework_locust-1.0.1/src/LocustLibrary/k6/__init__.py +1 -0
  13. robotframework_locust-1.0.1/src/LocustLibrary/k6/cli.py +66 -0
  14. robotframework_locust-1.0.1/src/LocustLibrary/k6/emit.py +69 -0
  15. robotframework_locust-1.0.1/src/LocustLibrary/k6/options.py +128 -0
  16. robotframework_locust-1.0.1/src/LocustLibrary/k6/profile.py +130 -0
  17. robotframework_locust-1.0.1/src/LocustLibrary/k6/robot_files.py +127 -0
  18. robotframework_locust-1.0.1/src/LocustLibrary/k6/scan.py +195 -0
  19. robotframework_locust-1.0.1/src/LocustLibrary/parsing.py +80 -0
  20. robotframework_locust-1.0.1/src/LocustLibrary/reporting.py +108 -0
  21. robotframework_locust-1.0.1/src/LocustLibrary/runner.py +135 -0
  22. robotframework_locust-1.0.1/src/LocustLibrary/scenario.py +102 -0
  23. robotframework_locust-1.0.1/src/LocustLibrary/shape.py +33 -0
  24. robotframework_locust-1.0.1/src/LocustLibrary/shared.py +28 -0
  25. robotframework_locust-1.0.1/src/LocustLibrary/stats.py +81 -0
  26. robotframework_locust-1.0.1/src/LocustLibrary/stoprules.py +93 -0
  27. robotframework_locust-1.0.1/src/LocustLibrary/studio/__init__.py +3 -0
  28. robotframework_locust-1.0.1/src/LocustLibrary/studio/app.py +170 -0
  29. robotframework_locust-1.0.1/src/LocustLibrary/studio/build_tab.py +73 -0
  30. robotframework_locust-1.0.1/src/LocustLibrary/studio/fonts/Inter-Medium.ttf +0 -0
  31. robotframework_locust-1.0.1/src/LocustLibrary/studio/fonts/Inter-OFL.txt +92 -0
  32. robotframework_locust-1.0.1/src/LocustLibrary/studio/fonts/Inter-Regular.ttf +0 -0
  33. robotframework_locust-1.0.1/src/LocustLibrary/studio/fonts/Inter-SemiBold.ttf +0 -0
  34. robotframework_locust-1.0.1/src/LocustLibrary/studio/fonts/JetBrainsMono-Medium.ttf +0 -0
  35. robotframework_locust-1.0.1/src/LocustLibrary/studio/fonts/JetBrainsMono-OFL.txt +93 -0
  36. robotframework_locust-1.0.1/src/LocustLibrary/studio/fonts/JetBrainsMono-Regular.ttf +0 -0
  37. robotframework_locust-1.0.1/src/LocustLibrary/studio/fonts.py +17 -0
  38. robotframework_locust-1.0.1/src/LocustLibrary/studio/live.py +131 -0
  39. robotframework_locust-1.0.1/src/LocustLibrary/studio/panels.py +139 -0
  40. robotframework_locust-1.0.1/src/LocustLibrary/studio/report_tab.py +50 -0
  41. robotframework_locust-1.0.1/src/LocustLibrary/studio/run_tab.py +187 -0
  42. robotframework_locust-1.0.1/src/LocustLibrary/studio/sidebar.py +82 -0
  43. robotframework_locust-1.0.1/src/LocustLibrary/studio/themes.py +83 -0
  44. robotframework_locust-1.0.1/src/LocustLibrary/studio/worker.py +39 -0
  45. robotframework_locust-1.0.1/src/LocustLibrary/suiteplan.py +76 -0
  46. robotframework_locust-1.0.1/src/LocustLibrary/users.py +153 -0
  47. robotframework_locust-1.0.1/src/LocustLibrary/validation.py +55 -0
  48. robotframework_locust-1.0.1/src/LocustLibrary/webui.py +32 -0
  49. robotframework_locust-1.0.1/src/robotframework_locust.egg-info/PKG-INFO +178 -0
  50. robotframework_locust-1.0.1/src/robotframework_locust.egg-info/SOURCES.txt +86 -0
  51. robotframework_locust-1.0.1/src/robotframework_locust.egg-info/dependency_links.txt +1 -0
  52. robotframework_locust-1.0.1/src/robotframework_locust.egg-info/entry_points.txt +3 -0
  53. robotframework_locust-1.0.1/src/robotframework_locust.egg-info/requires.txt +12 -0
  54. robotframework_locust-1.0.1/src/robotframework_locust.egg-info/top_level.txt +1 -0
  55. robotframework_locust-1.0.1/tests/test_calllog.py +70 -0
  56. robotframework_locust-1.0.1/tests/test_ceiling.py +38 -0
  57. robotframework_locust-1.0.1/tests/test_csv_cells.py +16 -0
  58. robotframework_locust-1.0.1/tests/test_distributed.py +22 -0
  59. robotframework_locust-1.0.1/tests/test_feed.py +85 -0
  60. robotframework_locust-1.0.1/tests/test_gaps.py +154 -0
  61. robotframework_locust-1.0.1/tests/test_guards.py +151 -0
  62. robotframework_locust-1.0.1/tests/test_hardening.py +137 -0
  63. robotframework_locust-1.0.1/tests/test_k6_cli.py +67 -0
  64. robotframework_locust-1.0.1/tests/test_k6_emit.py +174 -0
  65. robotframework_locust-1.0.1/tests/test_k6_hostile.py +71 -0
  66. robotframework_locust-1.0.1/tests/test_k6_options.py +96 -0
  67. robotframework_locust-1.0.1/tests/test_k6_scan.py +116 -0
  68. robotframework_locust-1.0.1/tests/test_mr_guard.py +76 -0
  69. robotframework_locust-1.0.1/tests/test_pacing.py +32 -0
  70. robotframework_locust-1.0.1/tests/test_python_path.py +24 -0
  71. robotframework_locust-1.0.1/tests/test_python_tasks.py +48 -0
  72. robotframework_locust-1.0.1/tests/test_requests.py +85 -0
  73. robotframework_locust-1.0.1/tests/test_rest.py +162 -0
  74. robotframework_locust-1.0.1/tests/test_run_logging.py +124 -0
  75. robotframework_locust-1.0.1/tests/test_runner.py +74 -0
  76. robotframework_locust-1.0.1/tests/test_shape.py +149 -0
  77. robotframework_locust-1.0.1/tests/test_shared_values.py +38 -0
  78. robotframework_locust-1.0.1/tests/test_stats.py +22 -0
  79. robotframework_locust-1.0.1/tests/test_stats_rows.py +34 -0
  80. robotframework_locust-1.0.1/tests/test_stop_rules.py +129 -0
  81. robotframework_locust-1.0.1/tests/test_studio_live.py +99 -0
  82. robotframework_locust-1.0.1/tests/test_studio_panels.py +27 -0
  83. robotframework_locust-1.0.1/tests/test_suiteplan.py +75 -0
  84. robotframework_locust-1.0.1/tests/test_transport.py +53 -0
  85. robotframework_locust-1.0.1/tests/test_user_classes.py +77 -0
  86. robotframework_locust-1.0.1/tests/test_user_numbers.py +53 -0
  87. robotframework_locust-1.0.1/tests/test_verdict_env.py +55 -0
  88. robotframework_locust-1.0.1/tests/test_version.py +7 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Abdulwahab Isam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,178 @@
1
+ Metadata-Version: 2.4
2
+ Name: robotframework-locust
3
+ Version: 1.0.1
4
+ Summary: Robot Framework library for authoring and running Locust load tests in RF syntax
5
+ Author-email: Abdulwahab Isam <abdoi94.iq@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://ai94iq.github.io/robotframework-locust/
8
+ Project-URL: Documentation, https://ai94iq.github.io/robotframework-locust/keywords.html
9
+ Project-URL: PyPI, https://pypi.org/project/robotframework-locust/
10
+ Project-URL: Source, https://github.com/ai94iq/robotframework-locust
11
+ Project-URL: Issues, https://github.com/ai94iq/robotframework-locust/issues
12
+ Project-URL: Changelog, https://github.com/ai94iq/robotframework-locust/blob/main/CHANGELOG.md
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Framework :: Robot Framework
15
+ Classifier: Framework :: Robot Framework :: Library
16
+ Classifier: Topic :: Software Development :: Testing
17
+ Classifier: Topic :: System :: Benchmark
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.11
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: robotframework>=7.5
26
+ Requires-Dist: robotframework-pythonlibcore>=4.6.0
27
+ Requires-Dist: locust<3,>=2.30
28
+ Requires-Dist: greenlet>=3.0
29
+ Provides-Extra: studio
30
+ Requires-Dist: PySide6>=6.8; extra == "studio"
31
+ Requires-Dist: pyqtgraph>=0.13; extra == "studio"
32
+ Provides-Extra: k6
33
+ Requires-Dist: tree-sitter>=0.26.1; extra == "k6"
34
+ Requires-Dist: tree-sitter-javascript>=0.25.0; extra == "k6"
35
+ Dynamic: license-file
36
+
37
+ # robotframework-locust
38
+
39
+ [Website](https://ai94iq.github.io/robotframework-locust/) | [PyPI](https://pypi.org/project/robotframework-locust/) |
40
+ [Keyword reference](https://ai94iq.github.io/robotframework-locust/keywords.html)
41
+
42
+ A Robot Framework library that builds and runs Locust load tests. You write
43
+ the load as a Robot suite: the library creates the Locust users, runs them
44
+ headless and checks the stats with keywords. Locust Studio shows a run live,
45
+ and `rflocust-k6` turns a k6 script into a Robot project.
46
+
47
+ Site and keyword reference: `docs/index.html` and `docs/keywords.html`,
48
+ served as the repo's GitHub page.
49
+
50
+ ![Locust Studio after a 20-user run](docs/screenshots/studio-run.png)
51
+
52
+ ## Contents
53
+
54
+ - [Install](#install)
55
+ - [Write a load suite](#write-a-load-suite)
56
+ - [Watch it in Locust Studio](#watch-it-in-locust-studio)
57
+ - [Convert a k6 script](#convert-a-k6-script)
58
+ - [Safety limits](#safety-limits)
59
+ - [Documentation](#documentation)
60
+ - [For coding agents](#for-coding-agents)
61
+ - [Contributing](#contributing)
62
+ - [License](#license)
63
+
64
+ ## Install
65
+
66
+ Requires Python 3.11 or newer. Robot Framework 7.5 or newer and Locust (2.30
67
+ or newer, below 3) install with the library.
68
+
69
+ ```
70
+ pip install robotframework-locust
71
+ pip install "robotframework-locust[studio]" # adds locust-studio
72
+ pip install "robotframework-locust[k6]" # adds rflocust-k6
73
+ ```
74
+
75
+ From a checkout: `uv sync`, or `pip install .`.
76
+
77
+ ## Write a load suite
78
+
79
+ ```robotframework
80
+ *** Settings ***
81
+ Library LocustLibrary
82
+
83
+ *** Test Cases ***
84
+ Home Page Under Load
85
+ Create Load Test https://test.example.com allowed_hosts=test.example.com
86
+ Set Wait Time 1s 3s
87
+ Add Get Request home / expected_status=200
88
+ Add Get Request health /health weight=2 expected_status=200, 204
89
+ Add Stop Rule p95 > 2s for 10s
90
+ Set Load Stages 30s:10 1m:10 15s:0
91
+ Run Load Test max_users=50
92
+ Should Have No Failures
93
+ Should Meet Response Time home p95 800ms
94
+ Export Report home-run
95
+ ```
96
+
97
+ ```
98
+ robot home_load.robot
99
+ ```
100
+
101
+ The suite builds the users, runs them, then checks the numbers. Run Load Test
102
+ logs a stats table and sample calls, with secrets masked. Export Report writes
103
+ the Locust HTML report beside `log.html`.
104
+
105
+ The library has 28 keywords: user classes, pacing, stop rules, Python tasks,
106
+ per-user numbers, data handed between users, and checks for response time,
107
+ error rate and throughput. See [docs/library.md](docs/library.md).
108
+
109
+ ## Watch it in Locust Studio
110
+
111
+ ```
112
+ locust-studio
113
+ ```
114
+
115
+ Open a suite (Ctrl+O) and press Run (Ctrl+R). Studio runs the suite under
116
+ Robot and updates the stats table and Locust's three charts every second.
117
+ When the run ends, the Report tab opens the Robot log and the Locust report.
118
+ Studio has a dark and a light theme and runs on Windows and Linux. See
119
+ [docs/studio.md](docs/studio.md).
120
+
121
+ ![The Studio Run tab in the dark theme, during a run](docs/screenshots/studio-run-graphite.png)
122
+
123
+ ## Convert a k6 script
124
+
125
+ ```
126
+ rflocust-k6 checkout.js --out robot
127
+ robot -v ENV:dev robot/tests
128
+ ```
129
+
130
+ The converter reads the script's options with `k6 inspect` and scans its
131
+ functions for plain HTTP calls. Stages, thresholds and simple requests become
132
+ keywords. A function it cannot read becomes a Python task that raises
133
+ `NotImplementedError` until you port it, and a report lists each item as
134
+ mapped, approximate or hand port. The k6 binary must be on PATH.
135
+ `k6 inspect` runs the script's init code as you, so convert only scripts you
136
+ trust. See [docs/k6-converter.md](docs/k6-converter.md).
137
+
138
+ ## Safety limits
139
+
140
+ A load test can take a server down. These limits are built in:
141
+
142
+ - Run Load Test refuses a run above `max_users` (default 100).
143
+ - Create Load Test refuses a host that is not on `allowed_hosts`.
144
+ - `Add Stop Rule p95 > 1s for 10s` and `stop_on_fail_ratio` stop a run
145
+ early.
146
+ - `expected_text` fails a 200 that carries an error page.
147
+ - The Locust web UI and distributed mode bind 127.0.0.1 only.
148
+
149
+ Read [docs/safety.md](docs/safety.md) before you point a run at a host you do
150
+ not own.
151
+
152
+ ## Documentation
153
+
154
+ | Page | What it covers |
155
+ |---|---|
156
+ | [docs/library.md](docs/library.md) | Writing suites, every keyword, Python tasks, reports |
157
+ | [docs/safety.md](docs/safety.md) | Every limit and how to set it |
158
+ | [docs/studio.md](docs/studio.md) | Locust Studio |
159
+ | [docs/k6-converter.md](docs/k6-converter.md) | The k6 mapping, its limits, porting by hand |
160
+ | [docs/cli.md](docs/cli.md) | The commands and their options |
161
+ | [docs/keywords.html](docs/keywords.html) | Keyword reference, built by libdoc |
162
+ | [docs/references.md](docs/references.md) | Locust and Robot Framework sources |
163
+ | [CHANGELOG.md](CHANGELOG.md) | Changes per release |
164
+
165
+ ## For coding agents
166
+
167
+ `.skills/using-locust-library/SKILL.md` tells a coding agent how to write,
168
+ run and check a load suite with this library, with the safety limits first.
169
+ Copy the folder into your agent's skills folder to use it in another repo.
170
+
171
+ ## Contributing
172
+
173
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the setup, the checks and the rules
174
+ a change must keep.
175
+
176
+ ## License
177
+
178
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,142 @@
1
+ # robotframework-locust
2
+
3
+ [Website](https://ai94iq.github.io/robotframework-locust/) | [PyPI](https://pypi.org/project/robotframework-locust/) |
4
+ [Keyword reference](https://ai94iq.github.io/robotframework-locust/keywords.html)
5
+
6
+ A Robot Framework library that builds and runs Locust load tests. You write
7
+ the load as a Robot suite: the library creates the Locust users, runs them
8
+ headless and checks the stats with keywords. Locust Studio shows a run live,
9
+ and `rflocust-k6` turns a k6 script into a Robot project.
10
+
11
+ Site and keyword reference: `docs/index.html` and `docs/keywords.html`,
12
+ served as the repo's GitHub page.
13
+
14
+ ![Locust Studio after a 20-user run](docs/screenshots/studio-run.png)
15
+
16
+ ## Contents
17
+
18
+ - [Install](#install)
19
+ - [Write a load suite](#write-a-load-suite)
20
+ - [Watch it in Locust Studio](#watch-it-in-locust-studio)
21
+ - [Convert a k6 script](#convert-a-k6-script)
22
+ - [Safety limits](#safety-limits)
23
+ - [Documentation](#documentation)
24
+ - [For coding agents](#for-coding-agents)
25
+ - [Contributing](#contributing)
26
+ - [License](#license)
27
+
28
+ ## Install
29
+
30
+ Requires Python 3.11 or newer. Robot Framework 7.5 or newer and Locust (2.30
31
+ or newer, below 3) install with the library.
32
+
33
+ ```
34
+ pip install robotframework-locust
35
+ pip install "robotframework-locust[studio]" # adds locust-studio
36
+ pip install "robotframework-locust[k6]" # adds rflocust-k6
37
+ ```
38
+
39
+ From a checkout: `uv sync`, or `pip install .`.
40
+
41
+ ## Write a load suite
42
+
43
+ ```robotframework
44
+ *** Settings ***
45
+ Library LocustLibrary
46
+
47
+ *** Test Cases ***
48
+ Home Page Under Load
49
+ Create Load Test https://test.example.com allowed_hosts=test.example.com
50
+ Set Wait Time 1s 3s
51
+ Add Get Request home / expected_status=200
52
+ Add Get Request health /health weight=2 expected_status=200, 204
53
+ Add Stop Rule p95 > 2s for 10s
54
+ Set Load Stages 30s:10 1m:10 15s:0
55
+ Run Load Test max_users=50
56
+ Should Have No Failures
57
+ Should Meet Response Time home p95 800ms
58
+ Export Report home-run
59
+ ```
60
+
61
+ ```
62
+ robot home_load.robot
63
+ ```
64
+
65
+ The suite builds the users, runs them, then checks the numbers. Run Load Test
66
+ logs a stats table and sample calls, with secrets masked. Export Report writes
67
+ the Locust HTML report beside `log.html`.
68
+
69
+ The library has 28 keywords: user classes, pacing, stop rules, Python tasks,
70
+ per-user numbers, data handed between users, and checks for response time,
71
+ error rate and throughput. See [docs/library.md](docs/library.md).
72
+
73
+ ## Watch it in Locust Studio
74
+
75
+ ```
76
+ locust-studio
77
+ ```
78
+
79
+ Open a suite (Ctrl+O) and press Run (Ctrl+R). Studio runs the suite under
80
+ Robot and updates the stats table and Locust's three charts every second.
81
+ When the run ends, the Report tab opens the Robot log and the Locust report.
82
+ Studio has a dark and a light theme and runs on Windows and Linux. See
83
+ [docs/studio.md](docs/studio.md).
84
+
85
+ ![The Studio Run tab in the dark theme, during a run](docs/screenshots/studio-run-graphite.png)
86
+
87
+ ## Convert a k6 script
88
+
89
+ ```
90
+ rflocust-k6 checkout.js --out robot
91
+ robot -v ENV:dev robot/tests
92
+ ```
93
+
94
+ The converter reads the script's options with `k6 inspect` and scans its
95
+ functions for plain HTTP calls. Stages, thresholds and simple requests become
96
+ keywords. A function it cannot read becomes a Python task that raises
97
+ `NotImplementedError` until you port it, and a report lists each item as
98
+ mapped, approximate or hand port. The k6 binary must be on PATH.
99
+ `k6 inspect` runs the script's init code as you, so convert only scripts you
100
+ trust. See [docs/k6-converter.md](docs/k6-converter.md).
101
+
102
+ ## Safety limits
103
+
104
+ A load test can take a server down. These limits are built in:
105
+
106
+ - Run Load Test refuses a run above `max_users` (default 100).
107
+ - Create Load Test refuses a host that is not on `allowed_hosts`.
108
+ - `Add Stop Rule p95 > 1s for 10s` and `stop_on_fail_ratio` stop a run
109
+ early.
110
+ - `expected_text` fails a 200 that carries an error page.
111
+ - The Locust web UI and distributed mode bind 127.0.0.1 only.
112
+
113
+ Read [docs/safety.md](docs/safety.md) before you point a run at a host you do
114
+ not own.
115
+
116
+ ## Documentation
117
+
118
+ | Page | What it covers |
119
+ |---|---|
120
+ | [docs/library.md](docs/library.md) | Writing suites, every keyword, Python tasks, reports |
121
+ | [docs/safety.md](docs/safety.md) | Every limit and how to set it |
122
+ | [docs/studio.md](docs/studio.md) | Locust Studio |
123
+ | [docs/k6-converter.md](docs/k6-converter.md) | The k6 mapping, its limits, porting by hand |
124
+ | [docs/cli.md](docs/cli.md) | The commands and their options |
125
+ | [docs/keywords.html](docs/keywords.html) | Keyword reference, built by libdoc |
126
+ | [docs/references.md](docs/references.md) | Locust and Robot Framework sources |
127
+ | [CHANGELOG.md](CHANGELOG.md) | Changes per release |
128
+
129
+ ## For coding agents
130
+
131
+ `.skills/using-locust-library/SKILL.md` tells a coding agent how to write,
132
+ run and check a load suite with this library, with the safety limits first.
133
+ Copy the folder into your agent's skills folder to use it in another repo.
134
+
135
+ ## Contributing
136
+
137
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the setup, the checks and the rules
138
+ a change must keep.
139
+
140
+ ## License
141
+
142
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,103 @@
1
+ [build-system]
2
+ requires = ["setuptools>=84"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "robotframework-locust"
7
+ dynamic = ["version"]
8
+ description = "Robot Framework library for authoring and running Locust load tests in RF syntax"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.11"
13
+ authors = [{ name = "Abdulwahab Isam", email = "abdoi94.iq@gmail.com" }]
14
+ dependencies = [
15
+ "robotframework>=7.5",
16
+ "robotframework-pythonlibcore>=4.6.0",
17
+ "locust>=2.30,<3",
18
+ "greenlet>=3.0",
19
+ ]
20
+ classifiers = [
21
+ "Development Status :: 5 - Production/Stable",
22
+ "Framework :: Robot Framework",
23
+ "Framework :: Robot Framework :: Library",
24
+ "Topic :: Software Development :: Testing",
25
+ "Topic :: System :: Benchmark",
26
+ "Programming Language :: Python :: 3",
27
+ "Programming Language :: Python :: 3 :: Only",
28
+ "Operating System :: OS Independent",
29
+ "Typing :: Typed",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ studio = ["PySide6>=6.8", "pyqtgraph>=0.13"]
34
+ k6 = [
35
+ "tree-sitter>=0.26.1",
36
+ "tree-sitter-javascript>=0.25.0",
37
+ ]
38
+
39
+ [project.scripts]
40
+ locust-studio = "LocustLibrary.studio.app:main"
41
+ rflocust-k6 = "LocustLibrary.k6.cli:main"
42
+
43
+ [project.urls]
44
+ Homepage = "https://ai94iq.github.io/robotframework-locust/"
45
+ Documentation = "https://ai94iq.github.io/robotframework-locust/keywords.html"
46
+ PyPI = "https://pypi.org/project/robotframework-locust/"
47
+ Source = "https://github.com/ai94iq/robotframework-locust"
48
+ Issues = "https://github.com/ai94iq/robotframework-locust/issues"
49
+ Changelog = "https://github.com/ai94iq/robotframework-locust/blob/main/CHANGELOG.md"
50
+
51
+ [tool.setuptools.dynamic]
52
+ version = {attr = "LocustLibrary.__version__"}
53
+
54
+ [tool.setuptools.packages.find]
55
+ where = ["src"]
56
+
57
+ [tool.setuptools.package-data]
58
+ LocustLibrary = ["py.typed", "studio/fonts/*"]
59
+
60
+ [dependency-groups]
61
+ dev = [
62
+ "pytest>=8.0",
63
+ "pytest-cov>=5.0",
64
+ "ruff>=0.8",
65
+ "mypy>=1.13",
66
+ "bandit>=1.8",
67
+ "pip-audit>=2.7",
68
+ "detect-secrets>=1.5",
69
+ "tree-sitter>=0.26.1",
70
+ "tree-sitter-javascript>=0.25.0",
71
+ "robotframework-robocop>=9.4.0",
72
+ ]
73
+
74
+ [tool.ruff]
75
+ line-length = 100
76
+ target-version = "py311"
77
+
78
+ [tool.ruff.lint]
79
+ extend-select = ["I", "UP", "B", "SIM"]
80
+ # Robot Framework libraries use a CamelCase module name.
81
+ ignore = ["N999"]
82
+
83
+ [tool.bandit]
84
+ # Popen gets an argument list, no shell, after validate_locustfile.
85
+ skips = ["B404", "B603"]
86
+
87
+ [tool.mypy]
88
+ python_version = "3.11"
89
+ strict = true
90
+ ignore_missing_imports = true
91
+
92
+ [tool.pytest.ini_options]
93
+ testpaths = ["tests"]
94
+ addopts = "-q --cov=LocustLibrary --cov-report=term-missing"
95
+
96
+ [tool.coverage.run]
97
+ source = ["src/LocustLibrary"]
98
+ omit = ["src/LocustLibrary/studio/*"]
99
+ # Users run in gevent greenlets; without this, lines after a greenlet switch go unrecorded.
100
+ concurrency = ["gevent", "thread"]
101
+
102
+ [tool.coverage.report]
103
+ fail_under = 80
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,143 @@
1
+ """Robot Framework library for authoring and running Locust load tests in RF syntax."""
2
+
3
+ import subprocess
4
+ import sys
5
+
6
+ from robot.api import logger
7
+ from robot.api.deco import keyword
8
+
9
+ from .builder import BuildKeywords
10
+ from .calllog import MAX_FAILED, PER_NAME
11
+ from .checks import CheckKeywords
12
+ from .parsing import _parse_seconds, _ratio
13
+ from .runner import run_load_test
14
+ from .scenario import RunConfig, Scenario, Stats
15
+ from .shared import SharedKeywords
16
+
17
+ __version__ = "1.0.1"
18
+
19
+
20
+ class LocustLibrary(BuildKeywords, CheckKeywords, SharedKeywords):
21
+ """LocustLibrary drives load tests through Locust with RF-native syntax."""
22
+
23
+ ROBOT_LIBRARY_SCOPE = "SUITE"
24
+
25
+ def __init__(self, python_path: str = "") -> None:
26
+ """`python_path` is a folder searched for the modules Add Python Task names."""
27
+ if python_path and python_path not in sys.path:
28
+ sys.path.insert(0, python_path)
29
+ self._scenario: Scenario | None = None
30
+ self._scenarios: list[Scenario] = []
31
+ self._default: Scenario | None = None
32
+ self._config: RunConfig | None = None
33
+ self._stats: Stats | None = None
34
+ self._web_proc: subprocess.Popen[bytes] | None = None
35
+ self._dist_master: subprocess.Popen[bytes] | None = None
36
+ self._dist_workers: list[subprocess.Popen[bytes]] | None = None
37
+ self._shared = {}
38
+
39
+ @keyword
40
+ def run_load_test(self, users: int = 10, spawn_rate: float = 1.0,
41
+ run_time: str = "30s", iterations: int = 0,
42
+ max_users: int = 100, stop_on_fail_ratio: str = "0",
43
+ fail_ratio_warmup: str = "10s") -> None:
44
+ """Run the configured load test headless.
45
+
46
+ `iterations` stops every user after that many task runs in total, within `run_time`.
47
+ Stages from Set Load Stages replace `users`, `spawn_rate` and `run_time`.
48
+ A run that would start more than `max_users` users is refused before it starts.
49
+ The log gets a stats table and the first calls of every request name plus the failed ones.
50
+ `stop_on_fail_ratio` (`20%` or `0.2`; 0 is off) stops the run early once the share of
51
+ failed requests passes it after `fail_ratio_warmup`; the reason is logged as a warning.
52
+ """
53
+ if self._scenario is None or self._config is None:
54
+ raise RuntimeError("Call Create Load Test first.")
55
+ self._config.users = users
56
+ self._config.spawn_rate = spawn_rate
57
+ self._config.run_time = run_time
58
+ self._config.iterations = iterations
59
+ self._config.stop_on_fail_ratio = _ratio(stop_on_fail_ratio)
60
+ self._config.fail_ratio_warmup = _parse_seconds(fail_ratio_warmup)
61
+ self._check_ceiling(self._config, max_users)
62
+ self._shared.clear()
63
+ for host in dict.fromkeys(s.host for s in self._scenarios if not s.verify_tls):
64
+ logger.warn(f"TLS verification is off for {host}")
65
+ self._stats = run_load_test(self._scenarios, self._config)
66
+ if self._stats.stopped:
67
+ logger.warn(f"Load test {self._stats.stopped}")
68
+ if self._stats.cpu_busy:
69
+ logger.warn("Load generator CPU went over 90%; response times may be too high")
70
+ self._log_run(self._stats)
71
+ if self._stats.stop_failed:
72
+ raise AssertionError(f"Load test {self._stats.stopped}")
73
+
74
+ @keyword
75
+ def get_user_index(self) -> int:
76
+ """Return the number of the virtual user running this task, unique within the run.
77
+
78
+ Use it for a unique value or a data row per user, such as `${PREFIX}_${index}`.
79
+ """
80
+ from .users import current_user
81
+
82
+ return int(current_user().index)
83
+
84
+ @keyword
85
+ def get_user_iteration(self) -> int:
86
+ """Return how many task runs this virtual user has started, counting this one."""
87
+ from .users import current_user
88
+
89
+ return int(current_user().iteration)
90
+
91
+ def _log_run(self, stats: Stats) -> None:
92
+ from .reporting import stats_table_html
93
+
94
+ logger.info(stats_table_html(stats), html=True)
95
+ for block in stats.calls:
96
+ logger.info(block, html=True)
97
+ if stats.left_out:
98
+ logger.info(f"{stats.left_out} more calls not logged: the log keeps the first "
99
+ f"{PER_NAME} of each request name and up to {MAX_FAILED} failures.")
100
+
101
+ def _check_ceiling(self, config: RunConfig, max_users: int) -> None:
102
+ peak = max((s.users for s in config.stages), default=config.users)
103
+ peak = max(peak, sum(s.fixed_count for s in self._scenarios))
104
+ if peak > max_users:
105
+ raise ValueError(f"{peak} users is over max_users={max_users}; raise it on purpose")
106
+
107
+ @keyword
108
+ def start_locust_web(self, locustfile: str, port: int = 8089) -> None:
109
+ """Start Locust web UI as subprocess."""
110
+ from .webui import start_web_ui, stop_web_ui
111
+
112
+ if self._web_proc is not None:
113
+ stop_web_ui(self._web_proc)
114
+ self._web_proc = start_web_ui(locustfile, port=port)
115
+
116
+ @keyword
117
+ def stop_locust_web(self) -> None:
118
+ """Stop Locust web UI."""
119
+ from .webui import stop_web_ui
120
+
121
+ proc = self._web_proc
122
+ if proc is not None:
123
+ stop_web_ui(proc)
124
+ self._web_proc = None
125
+
126
+ @keyword
127
+ def run_distributed(self, locustfile: str, processes: int = 2) -> None:
128
+ """Run Locust in distributed mode."""
129
+ from .distributed import run_distributed as _run
130
+
131
+ self.stop_distributed()
132
+ self._dist_master, self._dist_workers = _run(
133
+ locustfile, processes=processes
134
+ )
135
+
136
+ @keyword
137
+ def stop_distributed(self) -> None:
138
+ """Stop the master and workers from Run Distributed."""
139
+ from .distributed import stop_distributed as _stop
140
+
141
+ _stop(self._dist_master, self._dist_workers)
142
+ self._dist_master = None
143
+ self._dist_workers = None