python - Nose 测试 : how to show customized logging

标签 python logging nose

我有以下 python 文件 fct.py。如果我直接在 python 或 ipython 中运行 test1() 或 test2(),我会得到:

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 和谷歌,但似乎找不到解决方案。感谢您的帮助或指点。

''' 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

最佳答案

nosetests --nologcapture fct.py

会成功的

关于python - Nose 测试 : how to show customized logging,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41424371/

相关文章:

tomcat - 如何为每个 tomcat 服务器实例编写唯一的日志文件?

未为测试生成器执行 Python nose 设置/拆卸类夹具方法

python - 用于 Nose 测试的 Django 用户设置

Python Pyramid - URL 调度和遍历问题与哈希 (/)

python - 使用Python将嵌套列表插入mysql数据库

python - 调用 Windows 脚本时 python 中的退出代码不正确

python - 覆盖范围是跳过返回语句

python - OpenStack中子带宽限制方法

c# - 打印 C# Web 服务的 SOAP 请求和响应

php - 将 trigger_error 限制在类范围内