从Python模块中的nosetests获取测试结果

时间:2014-06-18 14:15:14

标签: python python-2.7 nose

我正在运行一个使用这样的计时器运行nosetests的模块:

import nose
from nosetimer import plugin
from collections import defaultdict
import time
import pandas as pd

plugin = plugin.TimerPlugin()
plugin.enabled = True
plugin.timer_ok = 1000
plugin.timer_warning = 2000
plugin.timer_no_color = False
logList = defaultdict(list)

nose.run(plugins=[plugin])
result = plugin._timed_tests
for test in result:
    logList[test].append(result[test])

我想知道是否有可能将每个测试名称映射到通过/失败/错误,如下所示:

{
'example.file.path.test1': 'pass',
'example.file.path.test2': 'pass',
'example.file.test3': 'fail',
'example.file.test4': 'pass',
'example.file.path2.test5': 'error',
'example.file.path2.test6': 'pass'
}

但是没有阅读stdout。换句话说,是否存在鼻子存储此信息的位置?我一直在阅读文档和代码几个小时没有运气,所以我觉得我可能会遗漏一些东西。

2 个答案:

答案 0 :(得分:2)

这个数据是可用的,但至少就我所能想到的而言,唯一的方法就是使用nose插件界面编写自己的插件。插件并不是那么复杂,特别是对于这样的事情。你需要传递,失败/错误,并启动测试钩子,以及test.address(),以获得这样的工作,如果内存服务。

答案 1 :(得分:2)

你也可以捎带nosetests --with-xunitnose.plugins.xunit.Xunit),这将产生你的测试结果的xml。您可以轻松解析生成的xml并提取所需的数据。

相关问题