def run(self, result): """ Run the test case, storing the results in C{result}. First runs C{setUp} on self, then runs the test method (defined in the constructor), then runs C{tearDown}. As with the standard library L{unittest.TestCase}, the return value of these methods is disregarded. In particular, returning a L{Deferred<twisted.internet.defer.Deferred>} has no special additional consequences. @param result: A L{TestResult} object. """ log.msg("--> %s <--" % (self.id())) new_result = itrial.IReporter(result, None) if new_result is None: result = PyUnitResultAdapter(result) else: result = new_result result.startTest(self) (doSkip, skipReason) = self.getSkip() if doSkip: # don't run test methods that are marked as .skip result.addSkip(self, skipReason) result.stopTest(self) return self._passed = False self._warnings = [] self._installObserver() # All the code inside _runFixturesAndTest will be run such that warnings # emitted by it will be collected and retrievable by flushWarnings. _collectWarnings(self._warnings.append, self._runFixturesAndTest, result) # Any collected warnings which the test method didn't flush get # re-emitted so they'll be logged or show up on stdout or whatever. for w in self.flushWarnings(): try: warnings.warn_explicit(**w) except: result.addError(self, failure.Failure()) result.stopTest(self)
def run(self, result): self.res = result #dw: hack so that we can explicitly add errors from twisted.internet import reactor new_result = itrial.IReporter(result, None) if new_result is None: result = PyUnitResultAdapter(result) else: result = new_result self._timedOut = False if self._shared and self not in self.__class__._instances: self.__class__._instances.add(self) result.startTest(self) if self.getSkip(): # don't run test methods that are marked as .skip result.addSkip(self, self.getSkip()) result.stopTest(self) return self._installObserver() self._passed = False first = False if self._shared: first = self._isFirst() self.__class__._instancesRun.add(self) self._deprecateReactor(reactor) try: if first: d = self.deferSetUpClass(result) else: d = self.deferSetUp(None, result) cb = lambda x: self.clean_up(result, x) d.addBoth(cb) except: print "Error launching test: " + self.name self.clean_up(result, "error launching test") return None d.addErrback(self.last_errback) return d