from locust import HttpUser, task, tag, between
import logging
# Configure logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
class TestUser(HttpUser):
# Set base URL to httpbin
host = "https://httpbin.org"
wait_time = between(1, 2)
@tag('get')
@task
def test_get(self):
logger.debug("Executing GET request task - tags: api,get")
# The /get endpoint will return detailed request information
response = self.client.get("/get")
if response.status_code == 200:
logger.debug(f"GET request successful: {response.json()}")
@tag('post')
@task
def test_post(self):
logger.debug("Executing POST request task - tags: api,post")
# Send some test data
data = {"name": "test", "value": "123"}
# The /post endpoint will return the sent data and request information
response = self.client.post("/post", json=data)
if response.status_code == 200:
logger.debug(f"POST request successful: {response.json()}")
@tag('web')
@task
def test_html(self):
logger.debug("Executing HTML request task - tags: web")
# The /html endpoint will return a test HTML page
response = self.client.get("/html")
if response.status_code == 200:
logger.debug("HTML request successful")
Prerequisites
Description
When using exclude-tags to exclude more than two tags, this setting will not take effect.
If exclude-tags is set to only one tag, it works correctly.
Command line
locust -f locust_test.py --exclude-tags get,post --headless
Locustfile contents
Python version
3.10.15
Locust version
2.32.3
Operating system
MacBook Pro 2020