python - How would I pass variables to a `@events.test_start.add_listener` function
问题描述
I'm trying to run load tests with locust but I need to run some API calls before I start spawning workers. I already pass my user credentials as environment variables but I don't want to have to hard-code the host within the locustfile. I'm ideally looking to have something that looks like
@events.test_start.add_listener
def on_test_start(**kwargs):
init(host, username, password)
Where init
will take care of all of the initial API calls.
解决方案
The first parameter, environment
, to the init function contains locust settings in the parsed_options
dict. Try getting host from there.
Something like (untested)
@events.init.add_listener
def on_locust_init(environment, **kwargs):
init(environment.parsed_options[”host”], ...)
推荐阅读
- python - 用 pandas 绘制多索引数据
- ios - 如何自动设置约束以使 UIView 之间的距离一致?
- java - Does JVM use kotlinc for Kotlin?
- angular - TypeError: Cannot read property 'processPaymentFS' of undefined at Object.closed
- kubernetes - Kubernetes:网络策略 - 全部拒绝和全部允许
- java - 带有 MongoDB 的 MVC SpringBoot 应用程序
- android - 在 textWatcher 中搜索列表时 EditText 滞后
- c - 在 HashTable 中插入时出错
- java - 用于电子邮件域的 Java RegEx
- docker - 如何解决因错误代码 137 而被杀死的 docker 容器