Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting test results from nosetests in Python module

I'm running a module that runs nosetests with a timer like this:

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])

And I was wondering if it's possible to get a mapping of each test name to pass/fail/error like this:

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

But without reading stdout. In other words, is there a location that nose stores this information? I've been reading the documentation and code for hours with no luck, so I feel like I may be missing something.

like image 231
weskpga Avatar asked Mar 06 '26 14:03

weskpga


2 Answers

This data is available, but at least as far as I can recall off the top of my head, the only way at it is using the nose plugin interface to write your own plugin. Plugins aren't really that complicated though, especially for something like this. You'd need the pass, fail/error, and start test hooks, along with test.address(), to get something like this working, if memory serves.

like image 141
Silas Ray Avatar answered Mar 09 '26 03:03

Silas Ray


You can also piggy back on nosetests --with-xunit (nose.plugins.xunit.Xunit) that will produce an xml of your test results. You can easily parse the resulting xml and extract the data you want.

like image 22
Oleksiy Avatar answered Mar 09 '26 04:03

Oleksiy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!