import
them from your Locust tests. Create a module like custom_logger.py
and then import it with import custom_logger
at the top of your locustfile.
What libraries are for
- Reusable helpers (auth, signing, payload builders)
- Constants and configuration values
- Custom loggers and instrumentation
- Domain-specific client wrappers
Library files must end with
.py
. They are team-scoped and available to every worker at runtime.Using a library in a test
Structure and imports
- One module per file, e.g.,
utils.py
→import utils
- Subpackages are not supported; keep modules flat
- Avoid long import times; module code runs on import
Best practices
- Keep helpers pure and side-effect free when possible
- Version modules via names (e.g.,
auth_v2.py
) if making breaking changes - Add docstrings and clear function names for readability
Related
- See API:
POST /api/v2/library
to create modules programmatically - See API:
GET /api/v2/library
to list modules