如何在蝗虫的多个类中使用多个主机

2024-05-18 12:34:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要测试一些具有不同地址的API,我已经为Locust Tool创建了locustfile,如下所述,但只有api1在工作,api2中的端点没有被调用

from locust import HttpUser, task, between

class api1(HttpUser):

    host = 'http://localhost:6001'
    wait_time = between(2, 4)

    @task()
    def api1_ep1(self):
        self.client.post('/ep1')
        
    @task()
    def api1_ep2(self):
        self.client.post('/ep2')
        
class api2(HttpUser):

    host = 'http://localhost:6002'
    wait_time = between(2, 4)

    @task()
    def api2_ep1(self):
        self.client.post('/ep1')

    @task()
    def api2_ep2(self):
        self.client.post('/ep2')

我尝试了来自issue: 150的建议,并将完整路径设置为self.client.post('http://localhost:6001/ep1'),但同样的问题仍然存在


Tags: selfclientlocalhosthttphosttaskdefbetween

热门问题