def run(self, test): global TestSuite "Run the given test case or test suite." print("Self.Title="+self.title) TestSuite = ncore.XSuite(self.title) result = _TestResult(self.verbosity) test(result) self.stopTime = datetime.datetime.now() self.generateReport(test, result) print >>sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime) TestSuite.writeXml(self.jUnitResultOutputFolder) return result
def run(self, test): global TestSuite "Run the given test case or test suite." print("Self.Title="+self.title) TestSuite = ncore.XSuite(self.title) result = _TestResult(self.verbosity) test(result) self.stopTime = datetime.datetime.now() self.generateReport(test, result) duration = str(self.stopTime-self.startTime) sys.stderr.write('\n' + bcolors.BOLD + 'TEST RUN ENDED. DURATION: ' + duration + bcolors.ENDC + '\n') TestSuite.writeXml(self.jUnitResultOutputFolder, duration)
def startSuite(self, module): '''Start a new suite''' # Create a suite self.suite = ncore.XSuite(module) # Start it self.suite.start() # Clean STDOUT self.stderr.reset() # Clean STDERR self.stdout.reset() # Start recording STDOUT self.stderr.start() # Start recording STDERR self.stdout.start()
def finalize(self, result): '''Set the old standard outputs''' # Stop the current suite self.stopSuite() # Clean STDOUT recorder self.stderr.end() # Clean STDERR recorder self.stdout.end() # Check if fork if self.fork: # Results not directly collected, available only there fork_suite = ncore.XSuite('multiprocess') # Create a fake id for successful tests class FakeTest(object): # Store unique success ID def __init__(self, pos): self.pos = pos # Add ID function def id(self): return 'nose.multiprocess.success%d' % self.pos # Add success for i in range(result.testsRun): fork_suite.addTest( ncore.XTest(nconst.TEST_SUCCESS, FakeTest(i))) # Add errors for test, err in result.errors: fork_suite.addTest( ncore.XTest(nconst.TEST_ERROR, test, err=err)) # Add failures for test, err in result.failures: fork_suite.addTest(ncore.XTest(nconst.TEST_FAIL, test, err=err)) # Write fork_suite.writeXml(self.core_target)
REPORT_TEST_OUTPUT_TMPL = r""" %(id)s: %(output)s """ # variables: (id, output) # ------------------------------------------------------------------------ # ENDING # ENDING_TMPL = """<div id='ending'> </div>""" # -------------------- The end of the Template class ------------------- TestSuite = ncore.XSuite('') TestResult = unittest.TestResult class _TestResult(TestResult): # note: _TestResult is a pure representation of results. # It lacks the output and reporting ability compares to unittest._TextTestResult. def __init__(self, verbosity=1): TestResult.__init__(self) self.stdout0 = None self.stderr0 = None self.success_count = 0 self.failure_count = 0 self.error_count = 0 self.verbosity = verbosity # result is a list of result in 4 tuple