Locust:无法使用 env 文件中的配置值

问题描述 投票:0回答:1

我正在尝试运行 Locust 测试,但我无法使用 .env 文件值

.env 文件包含 「价值」:diuqriqjqj

在 locust.py 中我添加了

apiKey = os.environ.get("VALUE", "")
class Api(HttpUser):
    wait_time = between(1, 5)

    @task
    def test_api(self):
        self.client.get(
            f"/api/test/apiKey={apiKey}"
        )

我使用 Locust 运行

if test -f .env; then locust -f locust.py; fi

并接收连接错误。如果我对 apiKey 值进行硬编码,一切正常。

python environment-variables api-key locust
1个回答
0
投票
ifneq (,$(wildcard ./.env))
    include .env
    export
endif
        env VALUE =$(VALUE) locust -f locust.py
© www.soinside.com 2019 - 2024. All rights reserved.