Ejemplo n.º 1
0
 def test_tracebackFromFailure(self):
     """
     Errors added through the L{PyUnitResultAdapter} have the same traceback
     information as if there were no adapter at all.
     """
     try:
         1/0
     except ZeroDivisionError:
         exc_info = sys.exc_info()
         f = Failure()
     pyresult = pyunit.TestResult()
     result = PyUnitResultAdapter(pyresult)
     result.addError(self, f)
     self.assertEqual(pyresult.errors[0][1],
                      ''.join(traceback.format_exception(*exc_info)))
Ejemplo n.º 2
0
    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