最佳答案
我正在使用 PyDev 进行 Python 应用程序的开发和单元测试。 As for unit-testing, everything works great except the fact that no content is logged to the logging framework. The logger is not captured by the "Captured output" of PyDev.
我已经将记录的所有内容转发到标准输出,如下所示:
import sys
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))
然而,“捕获的输出”并不显示记录到日志的内容。
下面是一个 unittest-script 示例: < em > test.py
import sys
import unittest
import logging
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))
class TestCase(unittest.TestCase):
def testSimpleMsg(self):
print("AA")
logging.getLogger().info("BB")
控制台输出如下:
Finding files... done.
Importing test modules ... done.
testSimpleMsg (itf.lowlevel.tests.hl7.TestCase) ... AA
2011-09-19 16:48:00,755 - root - INFO - BB
BB
ok
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
但测试的 捕获输出是:
======================== CAPTURED OUTPUT =========================
AA
有人知道如何捕获在执行此测试期间记录到 logging.Logger
的所有内容吗?