Pytest 日志消息出现两次
Pytest Logging messages appear twice
我的测试框架结构如下
- Master_test_Class.py ---> 将通用测试用例保存为 运行 冒烟和回归测试套件
- Test_Smoke1.py 和 Test_Reg1.py --> Child 类 继承 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
我很迷茫为什么日志信息打印了两次。
这可能是因为您有一个将日志发送到标准输出的日志记录处理程序,解决方案是 运行 pytest
不带参数 -s
(这假设日志有您需要的所有信息)或删除使用标准输出的日志记录处理程序。
如果您只想查看日志记录模块的输出,请使用 --log-cli-level=INFO
作为 pytest 测试 运行 的参数。由于 -s
开关,您看到它两次。并且,要测试它是相同的日志还是不同的,请在日志消息中添加时间戳。
我的测试框架结构如下
- Master_test_Class.py ---> 将通用测试用例保存为 运行 冒烟和回归测试套件
- Test_Smoke1.py 和 Test_Reg1.py --> Child 类 继承 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
我很迷茫为什么日志信息打印了两次。
这可能是因为您有一个将日志发送到标准输出的日志记录处理程序,解决方案是 运行 pytest
不带参数 -s
(这假设日志有您需要的所有信息)或删除使用标准输出的日志记录处理程序。
如果您只想查看日志记录模块的输出,请使用 --log-cli-level=INFO
作为 pytest 测试 运行 的参数。由于 -s
开关,您看到它两次。并且,要测试它是相同的日志还是不同的,请在日志消息中添加时间戳。