Reputation: 1966
I am using nose to run a bunch of test cases. I would like to record output of each case to separate files, and to know result[success/failure] of each case. unfortunately, I can not figure out how to do it with nose. can anybody provide some clues? thank you
Upvotes: 1
Views: 1333
Reputation: 13940
Firstly, this sounds like unusual usage, and may indicate that you should rethink your testing scheme.
I can think of a couple of ways to address this. The simplest would be to have each test log itself instead of having nose do it for you. If you have only a few tests, or only care to log the results of a few tests, this would definitely be the way to do it.
A more complex and general approach would be to write a nose plug-in that records the result of each test as it finishes. To do this, you'd want to write a plug-in that implements the afterTest() method.
from nose.plugins import Plugin
import datetime
class SeparateReports(Plugin):
"Log the results of each test into a separate file."
def afterTest(self, test):
logname = test.id() + '.log'
success = test.passed
date = datetime.datetime.now()
# print logname, datetime.datetime.now(), success
with open(logname, 'a') as log:
log.write("%s: %s\n" % (date, success))
This will append to a logfile named after your specific test a datestamp and True for success/False for failure. A couple of notes:
Upvotes: 5