前言
通过使用@tag装饰器标记任务,可以使用--tags和
--exclude-tags
参数对测试期间执行的方法进行选择。仅有被选择的方法才会执行或者不执行,当然该方法必须要先被@task标识。
--tags
from locust import HttpUser, task, TaskSet, tag
import os
class Test1(TaskSet):
@tag('测试1')
@task
def test01(self):
print("测试01")
@tag('测试1','测试2')
@task
def test02(self):
print("测试02")
@tag('测试3')
@task
def test03(self):
print("测试03")
class Test(HttpUser):
tasks = [Test1]
# min_wait = 100
# max_wait = 1000
#执行命令locust -f test_01.py --host=http://127.0.0.1 --tags 测试1
HttpUser只会执行在命令行中使用--tags后跟上标识名称的方法,多个名称间用空格分割执行结果如下:
--exclude-tags
from locust import HttpUser, task, TaskSet, tag
import os
class Test1(TaskSet):
@tag('测试1')
@task
def test01(self):
print("测试01")
@tag('测试1','测试2')
@task
def test02(self):
print("测试02")
@tag('测试3')
@task
def test03(self):
print("测试03")
class Test(HttpUser):
tasks = [Test1]
# min_wait = 100
# max_wait = 1000
#执行命令locust -f test_01.py --host=http://127.0.0.1 --exclude-tags 测试1
HttpUser会排出执行在命令行中使用--tags后跟上标识名称的方法,多个名称间用空格分割执行结果如下: