Django Nose - 需要在运行测试时捕获输出

时间:2016-08-18 20:50:18

标签: python django django-nose

我正在使用call_command在管理命令中运行django-nose测试。我需要捕获输出并使用它做一些事情,具体取决于它是否失败或通过。 我目前在管理命令中的代码:

content = StringIO()
try:
    call_command('test', '--nologcapture', '-s', stdout=content)
        # since its calling system exit
except BaseException:
    pass
content.seek(0)
print content.read(), '<-- content'

# Check if test is passed and do something or else something else.

就我而言,内容始终是空字符串。

我尝试了很多鼻子插件,但无法获取输出。

感谢。

0 个答案:

没有答案