Locust Single Runner
A professional VSCode extension that adds "Run Test" buttons to individual Locust test methods, enabling efficient single-scenario testing with a single click.
✨ Features
- 🎯 Single Click Testing: Execute individual Locust test methods without running the entire test suite
- 🔍 Smart Detection: Automatically detects Locust files in
ci-test/loadtests
directories
- 📊 Real-time Output: View test results directly in VSCode output panel with detailed logging
- ⚙️ Configurable: Customize Python path and execution timeout
- 🚀 Performance Optimized: Efficient CodeLens provider with minimal resource usage
- 🛡️ Error Handling: Comprehensive error handling with user-friendly notifications
🚀 How it Works
The extension adds a "$(play) Run {method_name}" CodeLens above each test method in your Locust files. When clicked, it executes:
python3 <locustfile> run_scenario <method_name>
Example:
python3 locustfile_allrequests.py run_scenario post_orderitems_cancel
📋 Requirements
- Directory Structure: Locust files must be in a
ci-test/loadtests
directory
- File Naming: Files must contain
locust
in the filename
- Decorator: Locust classes must use the
@enable_single_test_runner
decorator
- Method Naming: Test methods should start with:
get_
, post_
, put_
, patch_
, or delete_
- Python: Python 3.x installed and accessible via PATH
🎮 Usage
- Open a Locust file in the
ci-test/loadtests
directory
- Look for "$(play) Run {method_name}" buttons above your test methods
- Click the button to run that specific test
- View results in the "Locust Single Runner" output panel
⚙️ Configuration
Configure the extension via VSCode settings:
{
"locustSingleRunner.pythonPath": "python3",
"locustSingleRunner.timeout": 60000,
"locustSingleRunner.useTerminal": true
}
Available Settings
Setting |
Type |
Default |
Description |
locustSingleRunner.pythonPath |
string |
python3 |
Path to Python executable |
locustSingleRunner.timeout |
number |
60000 |
Command timeout in milliseconds (output panel only) |
locustSingleRunner.useTerminal |
boolean |
true |
Run commands in VSCode terminal instead of output panel |
Example Locust File
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib', 'cs-locust'))
from cs_locust import BaseSequentialUser, enable_single_test_runner
@enable_single_test_runner
class MyTestUser(BaseSequentialUser):
def post_order_create(self): # ▶️ Run Test button will appear here
# Your test code here
pass
def get_order_status(self): # ▶️ Run Test button will appear here
# Your test code here
pass
Development
To run the extension in development mode:
- Clone this repository
- Run
npm install
- Run
npm run compile
- Press F5 to launch a new Extension Development Host window
License
MIT