英文:
Python Locust how to print to console and debug
问题
我有这个Python - Locust脚本:
from locust import HttpUser, between, task
class LoadValues(HttpUser):
def _run_read_ts(self, series_list, resolution, start, end):
tsIds = ",".join(series_list)
resp = self.client.get(f'/api/loadValues?tsIds={tsIds}&resolution={resolution}&startUtc={start}&endUtc={end}',
headers={'X-API-KEY': 'sss='})
print("Response content:", resp.text)
@task
def test_get(self):
self._run_read_ts([98429], 'PT1H', '2020-05-11T09%3A17%3A47.478Z', '2023-05-11T09%3A17%3A47.478Z')
我尝试使用 print("Response content:", resp.text) 打印上面的内容,但在PowerShell中看不到任何内容。
我可以在哪里看到响应?
英文:
I have this Python - Locust script:
from locust import HttpUser, between, task
class LoadValues(HttpUser):
def _run_read_ts(self, series_list, resolution, start, end):
tsIds = ",".join(series_list)
resp= self.client.get(f'/api/loadValues?tsIds={tsIds}&resolution={resolution}&startUtc= {start}&endUtc={end}',
headers={'X-API-KEY': 'sss='})
print("Response content:", resp.text)
@task
def test_get(self):
self._run_read_ts([98429], 'PT1H', '2020-05-11T09%3A17%3A47.478Z', '2023-05-11T09%3A17%3A47.478Z')
I have tried to print above using "print("Response content:", resp.text)"
But do not see anything in the power shell.
Where can I see the response?
答案1
得分: 1
Locust文档解释了Locust使用logging,这可以防止print语句到达标准输出。但是你可以自己使用logging。
import logging
logging.info("此日志消息将发送到其他Locust日志消息的位置")
英文:
The Locust docs explain that Locust uses logging, which can prevent print statements from reaching stdout. But you can just use logging yourself.
import logging
logging.info("this log message will go wherever the other locust log messages go")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论