2014-06-18 29 views
3

我正在运行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' 
} 

但没有读取标准输出。换句话说,有没有一个位置可以存储这些信息?我一直在阅读文档和代码几个小时没有运气,所以我觉得我可能会错过一些东西。

回答

2

这个数据是可用的,但至少在我能够回想起我的头顶时,唯一的方法就是使用鼻插件接口来编写自己的插件。插件并不是那么复杂,特别是对于这样的事情。你需要pass,fail/error和start测试钩子以及test.address()来获得像这样的工作,如果内存服务的话。

+0

我知道我可以用插件做,但我希望有一个更简单的方法来获得这些结果。如果可能的话,我想单独离开setup.py。 – weskpga

+0

我非常肯定,如果有什么工作,它将是一个无证的破解,这意味着你必须自己的代码。 –

+0

无证黑客是要走的路。 – weskpga

2

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