The good news is that it's really easy to implement a "poor man's" version of a unittest:
totalErrors = 0 totalTests = 0 def assertTrue(booleanCondition, message): global totalTests, totalErrors totalTests = totalTests + 1 if (not booleanCondition): print "ERROR:", message totalErrors = totalErrors + 1 #your testing code here assertTrue(domain is not None, "domain is not None") #print test summary print "" print "totalTests=", totalTests if (totalErrors == 0): print 'SUCCESS' else: print 'FAILURE, totalErrors=', totalErrors
One big step forward it to use the inspect module to print the actual assertTrue statement being executed - so you avoid having to pass also the message:
import inspect totalErrors = 0 totalTests = 0 def assertTrue(booleanCondition, message): global totalTests, totalErrors totalTests = totalTests + 1 if (not booleanCondition): frame,filename,line_number,function_name,lines,index = inspect.stack()[1] print "ERROR:", message, frame,filename,line_number,function_name,lines,index totalErrors = totalErrors + 1 #your testing code here assertTrue(domain is not None) #print test summary print "" print "totalTests=", totalTests if (totalErrors == 0): print 'SUCCESS' else: print 'FAILURE, totalErrors=', totalErrors
I love being minimalistic and lazy....
No comments:
Post a Comment