【问题标题】:Pytest Logging messages appear twicePytest Logging 消息出现两次
【发布时间】:2021-10-12 21:03:37
【问题描述】:

我的测试框架有以下结构

  • Master_test_Class.py ---> 保存为冒烟和回归测试套件运行的通用测试用例
  • Test_Smoke1.py 和 Test_Reg1.py --> 子类继承 Master_test_class.py

我在 pytest.ini 中为 INFO 启用了日志记录

[pytest]
log_cli = 1 
log_cli_level = INFO

下面是我在 conftest.py 中的代码

def pytest_generate_tests(metafunc):
.....
logging.info("This is generated during the test collection !!!")

当我运行任何一个测试文件的测试时,日志会以 pytest.ini 中指定的格式打印两次,然后以红色打印一次

pytest -s Test_Reg1.py

我很迷茫,为什么日志信息会被打印两次。

【问题讨论】:

  • 请分享记录器配置。

标签: python unit-testing logging pytest


【解决方案1】:

这可能是因为您有一个将日志发送到标准输出的日志记录处理程序,解决方案是运行pytest 不带参数-s(这假设日志包含您需要的所有信息)或删除日志记录使用标准输出的处理程序。

【讨论】:

    【解决方案2】:

    如果您只想查看日志记录模块的输出,请使用--log-cli-level=INFO 作为 pytest 测试运行的参数。由于-s 开关,您看到它两次。并且,要测试它是相同的日志还是不同的日志,请在日志消息中添加时间戳。

    【讨论】:

      猜你喜欢
      • 2013-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多