Python Locust如何在控制台打印和调试

huangapple go评论58阅读模式
英文:

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")

huangapple
  • 本文由 发表于 2023年6月2日 13:25:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76387340.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定