2017-01-02 84 views
2

我有以下python文件fct.py.如果我直接运行在Python或IPython中test1的()或TEST2(),我得到:nosetests:如何显示自定义日志记录

In [315]: test1() 
fct - fct.py[line:9] 2017-01-02 17:23:22,992 : DEBUG : debug output 

In [316]: test2() 
fct - fct.py[line:9] 2017-01-02 17:23:26,393 : DEBUG : debug output  

如果我运行

nosetests -v fct.py 

我得到:

test1 logging ... ok 
test2 logging ... ok 
Ran 2 tests in 0.000s 

OK  

无日志输出“调试输出“。

如何在nosetests中获取日志消息“调试输出”?我读了一些nosetests -h和google,但似乎找不到解决方案。感谢您的帮助或指点。

''' fct.py ''' 
import logging 

LOGGER = logging.getLogger(__name__) 
LOGGER.addHandler(logging.NullHandler()) 

def fct(): 
    ''' fct logging ''' 
    LOGGER.debug(" debug output") 

def test1(): 
    ''' test1 logging ''' 
    fct() 
    assert 1==1 

def test2(): 
    ''' test2 logging ''' 
    logging.basicConfig(level=logging.DEBUG) 
    fct() 
    assert 1==1 

回答

1
nosetests --nologcapture fct.py 

会做的伎俩

相关问题