Replies: 4 comments 4 replies
-
I think this is super interesting. I basically had to ”hack” locust-plugins into locust core by adding a import-for-side effects, and I’ve always wanted to do it nicer. I think your approach makes sense. Just one question: With pytest support integrated into locust (since the latest release) is there a ”pytest” way to do this, perhaps we can use that? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the feedback 🙏 — you’re right, what I’m suggesting is basically the same kind of plugin architecture that pytest uses. From a Locust perspective I was imagining:
My understanding (I might be wrong!) is that pytest loads all discovered plugins by default and you can disable them with Either way could work — pytest’s style would feel familiar to many users, but I personally like the clarity of requiring explicit activation. |
Beta Was this translation helpful? Give feedback.
-
Rough Idea: I think it would make sense to load plugins right after this line. Line 175 in 1144476 That way, all plugin event handlers are registered first, and then the event handlers defined in locustfile.py are attached afterwards. This ensures that user-defined handlers in the locustfile run after any plugin logic, which makes the event order easier to understand. |
Beta Was this translation helpful? Give feedback.
-
I think we can go ahead and enable installed plugins by default and have an opt-out model like pytest. 999/1000 times if a user has a plugin installed they'll wanna enable it :) Other than that your approach looks great! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
✨ Feature Request:
--plugins
Flag for Explicit Plugin LoadingProblem
Locust is very extensible through events, but today plugins can only be activated by importing them in
__init__.py
or directly insidelocustfile.py
.This has a few drawbacks:
Proposal
Add a
--plugins
flag to the CLI:Locust would import each plugin and call a
load(options)
function if it exists. This makes plugin activation explicit and avoids side effects.How It Could Work
Plugins declare themselves via Python entry points (e.g., in
pyproject.toml
orsetup.py
):At startup, Locust discovers all registered plugins through the
locust.plugins
entry point group.For each discovered plugin, locust loads the entry point corresponding to the given
--plugin
Benefits
load()
, no hidden side effects.locust --list-plugins
).Final Note
This is just a proposal. I’d be happy to hear feedback or learn about existing recommended approaches if I’ve missed something. 🙏
Beta Was this translation helpful? Give feedback.
All reactions