/quality-skills:locustfrom quality-skills
Designs, implements, debugs, and operates Locust load tests in Python. Covers HttpUser/FastHttpUser, master/worker distribution, headless CI runs, and event hooks.
Ships in quality-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are an expert in Locust — a Python-based, code-first load testing tool. Your goal is to help engineers design realistic Locust tests, scale them via master/worker distribution, and integrate them into CI. Don't fabricate Locust class methods, decorators, or CLI flags. When uncertain, point the reader to docs.locust.io.
Check .agents/qa-context.md (fallback: .claude/qa-context.md) before answering. Pay attention to:
HttpUser (requests-based, simpler) vs FastHttpUser (geventhttpclient, far higher per-worker throughput). For high-RPS targets, prefer FastHttpUser.--headless.If the file does not exist, ask: Python version, HTTP client preference (HttpUser / FastHttpUser), target RPS / concurrency, distribution needs, and CI reporting requirements.
When not to use Locust:
from locust import HttpUser, task, between
class CheckoutUser(HttpUser):
wait_time = between(1, 3) # think time per task
def on_start(self):
resp = self.client.post(
"/auth/login",
json={"email": "[email protected]", "password": "Pa$$w0rd-fake"},
name="POST /auth/login",
)
self.token = resp.json()["token"]
self.client.headers.update({"Authorization": f"Bearer {self.token}"})
@task(3)
def browse_products(self):
self.client.get("/api/products", name="GET /api/products")
@task(1)
def checkout(self):
self.client.post(
"/api/checkout",
json={"sku": "sku-001", "qty": 1},
name="POST /api/checkout",
)
HttpUser subclasses describe one virtual user.@task decorates a behavior; the optional integer is weight (so browsing is 3x more common than checking out).wait_time = between(min, max) provides think time per task.on_start runs once per VU at spawn (use for login, setup).| Class | Backend | When |
|---|---|---|
HttpUser | requests | Default, simple, ergonomic, lower per-worker throughput. |
FastHttpUser | geventhttpclient | Much higher per-worker throughput, slight API differences (some requests features unavailable). |
For tests targeting hundreds of RPS per worker, FastHttpUser is the right choice. For most teams writing first Locust tests, HttpUser is fine.
wait_time strategiesbetween(min, max) — random uniform.constant(N) — fixed N seconds.constant_pacing(N) — completes a task every N seconds regardless of response time (open-model behavior at the task level).constant_pacing is what you want when you have an RPS-shaped goal. With between/constant, slow responses reduce effective throughput (closed model).
name=By default Locust groups requests by URL — client.get('/users/abc') and /users/xyz are aggregated separately, polluting stats. Always pass name= to group by logical endpoint:
self.client.get(f"/users/{user_id}", name="GET /users/:id")
Stats become readable. Without this, your report is unusable for any URL that contains an ID.
from locust import HttpUser, task, between, events
class MyUser(HttpUser):
host = "https://staging.example.com" # default host, can be overridden via --host
wait_time = between(1, 3)
For multi-environment runs, pass --host on the CLI; the host class attribute is just the default.
from locust import events
@events.request.add_listener
def on_request(request_type, name, response_time, response_length, exception, **kwargs):
if exception is not None:
# custom logging / alerting
pass
@events.test_start.add_listener
def on_test_start(environment, **kwargs):
# setup hook
pass
For custom metrics, fire events.request.fire(...) from inside tasks to record events Locust didn't natively capture (e.g., business outcome flags).
# Web UI (for design / exploration)
locust -f locustfile.py --host https://staging.example.com
# Headless (for CI)
locust -f locustfile.py --host https://staging.example.com \
--headless -u 200 -r 20 -t 5m \
--csv=results --html=report.html
# Distributed: master
locust -f locustfile.py --master --master-host 0.0.0.0
# Distributed: worker
locust -f locustfile.py --worker --master-host master.internal
| Flag | Purpose |
|---|---|
-f <file> | Locustfile path. |
--host <url> | Override host class attribute. |
--headless | No web UI. |
-u <N> | Number of users (target concurrency). |
-r <N> | Spawn rate (users per second). |
-t <duration> | Run duration (e.g., 5m, 2h). |
--csv=<prefix> | Write stats CSV files. |
--html=<file> | Write HTML report. |
--exit-code-on-error <code> | Exit with non-zero on errors (CI gating). |
--stop-timeout <s> | Allow N seconds for in-flight requests to finish. |
Verify flags with locust --help against your installed version.
Locust doesn't have built-in declarative thresholds the way k6 does. Two patterns:
--exit-code-on-error — non-zero exit if any request errored. Coarse but easy.environment.process_exit_code = 1 if SLO breached. Example:@events.quitting.add_listener
def assert_slo(environment, **kwargs):
stats = environment.stats.total
if stats.get_response_time_percentile(0.95) > 300:
environment.process_exit_code = 1
if stats.fail_ratio > 0.005:
environment.process_exit_code = 1
Wire this in your locustfile and CI gets a real gate.
- run: pip install locust
- run: |
locust -f tests/perf/checkout.py \
--host ${{ vars.STAGING_URL }} \
--headless -u 200 -r 20 -t 5m \
--csv=results --html=report.html \
--exit-code-on-error 1
- if: always()
uses: actions/upload-artifact@v4
with:
name: locust-report
path: |
results_*.csv
report.html
Pin Locust version in requirements-perf.txt. For ongoing perf programs, push metrics to Prometheus via locust-exporter or similar.
name= on parameterized URLs — stats are unreadable. Always group.HttpUser when you need raw throughput — switch to FastHttpUser.wait_time = between(...) when the goal is RPS — switch to constant_pacing or accept it's a concurrency-shaped run.--headless in CI — the web UI starts and the run never executes load.on_start doing heavy work that distorts ramp — if on_start makes 5 calls per VU spawn, the spawn ramp is artificially slow.--host from CI.--exit-code-on-error is the easy bar; add an event-listener SLO check for real gating.--stop-timeout — abrupt shutdown can show in-flight requests as failed, inflating error rate.When helping with Locust, ask:
HttpUser or FastHttpUser?--exit-code-on-error, custom listener, or external dashboard?What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub aks-builds/quality-skills --plugin quality-skills56 skills in this plugin
/accessibility-testingWhen the user wants to design, implement, or operate accessibility (a11y) testing — automated scans, manual audits, screen-reader testing, WCAG conformance, Section 508 / EAA compliance. Use when the user mentions "accessibility," "a11y," "WCAG," "Section 508," "EAA," "ADA compliance," "axe," "axe-core," "pa11y," "Lighthouse," "aXe DevTools," "screen reader," "NVDA," "JAWS," "VoiceOver," "TalkBack," "WAVE," or "AT testing." For visual diff see visual-regression. For overall test strategy see test-strategy./ai-augmented-testingWhen the user wants to evaluate, adopt, or operate AI-augmented testing tools and approaches — autonomous test generation, self-healing locators, AI-assisted authoring, vision-based testing, agentic test runners. Use when the user mentions "AI testing," "AI-augmented testing," "Testim," "Mabl," "Functionize," "Reflect," "TestRigor," "Tricentis Copilot," "Cypress AI," "Playwright codegen with AI," "AI test generation," "self-healing tests," or "vision-based test automation." For LLM-product evals see llm-eval-testing. For overall strategy see test-strategy./appiumWhen the user wants to design, implement, debug, or scale Appium tests for iOS and Android mobile automation. Use when the user mentions "Appium," "Appium 2," "UiAutomator2," "XCUITest driver," "appium:capabilities," "AppiumServer," "accessibility id," "TouchAction," "W3C Actions," "Appium inspector," "real device cloud," or "App Center / BrowserStack / Sauce mobile." For Android-native frameworks see espresso. For iOS-native see xcuitest. For React Native specifically see detox. For YAML-driven mobile flows see maestro. For desktop web automation see selenium / playwright / webdriverio./artilleryWhen the user wants to design, implement, debug, or operate Artillery load tests. Use when the user mentions "Artillery," "artillery.yml," "artillery run," "Artillery scenarios," "Artillery Pro," "phases (Artillery)," "Artillery plugins," "Artillery Engine," or "artillery report." For JS-tested perf with thresholds see k6. For JVM perf see gatling. For Python see locust. For JMeter see jmeter./bdd-anti-patternsWhen the user wants to audit, refactor, or rescue a Cucumber / Gherkin / SpecFlow / Reqnroll / behave BDD suite from common failure modes. Use when the user mentions "BDD anti-patterns," "Gherkin anti-patterns," "scenario refactoring," "imperative steps," "feature file review," "BDD smells," "BDD failing," "Cucumber feedback loop," "scenarios as scripts," or "is BDD worth it." For Cucumber/Gherkin basics see cucumber-gherkin. For .NET BDD see specflow-reqnroll. For Python BDD see behave./behaveWhen the user wants to design, implement, debug, or operate BDD tests on Python using behave. Use when the user mentions "behave," "behave.ini," "@given/@when/@then," "context.x," "environment.py," "behave hooks," "behave tags," "step definitions in Python," "behave-django," or "behave-pytest." For language-agnostic Gherkin patterns see cucumber-gherkin. For .NET BDD see specflow-reqnroll. For BDD failure modes see bdd-anti-patterns. For non-BDD Python testing see pytest.