[Twisted-Python] need help figuring out weird pb/trial interaction

Jonathan Simms slyphon at twistedmatrix.com
Tue Nov 16 15:06:10 MST 2004


teratorn pasted the following code for me one night and was complaining that 
there was no traceback in the error reporting of trial. I spent about an hour
and a half stepping through this code with pdb, and afaict, this isn't a trial
bug. However, I don't understand why this is happening. 

---------------------------------------------
from twisted.internet import reactor
from twisted.trial import unittest
from twisted.trial.assertions import *
from twisted.trial import util
from twisted.spread import pb
from twisted.cred import portal, checkers, credentials, perspective
from zope.interface import implements
class MyRealm:
    implements(portal.IRealm)
    def requestAvatar(self, avatarId, mind, *interfaces):
        return (perspective.IPerspective, pb.Avatar(), lambda:None)
class LiveServerTestCase(unittest.TestCase):
    def setUp(self):
        self.realm = MyRealm()
        portal = pb.Portal(self.realm)
        checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(good='user')
        portal.registerChecker(checker)
        f = pb.PBServerFactory(portal)
        self.port = reactor.listenTCP(0, f, interface="127.0.0.1")
        self.portno = self.port.getHost().port
    def tearDown(self):
        self.port.stopListening()
 
    def testExample(self):
        f = pb.PBClientFactory()
        d = f.login(credentials.UsernamePassword("bad", "password"), "BRAINS!")
        c = reactor.connectTCP("127.0.0.1", self.portno, f)
        #this should throw an Exception because we're using the wrong user/pass
        #result = util.wait(d)
        #commenting the previous line, and uncommenting the next two lines
        #results in no output for the testExample ERROR
        d.addCallback(self._cb).addErrback(self._eb)
        return d
    def _cb(self, value):
        raise FailTest, "expecting Failure, got result"
    def _eb(self, failure):
        print failure
        return failure

----------------------------------------------



saving this and running trial teratorn.py i get the following output:


###-------------------------------------------------------------------------###


  teratorn
    LiveServerTestCase
      testExample ... [Failure instance: Traceback from remote host -- Traceback unavailable
]
                                                  [ERROR]
    cleanup errors                                           [ERROR]

/home/slyphon/Projects/Twisted/trunk/twisted/trial/reporter.py:258: twisted.trial.reporter.BrokenTestCaseWarning: REACTOR UNCLEAN! traceback(s) follow: 




===============================================================================
[ERROR]: testExample (teratorn.LiveServerTestCase)







-------------------------------------------------------------------------------
Ran 1 tests in 0.027s

FAILED (errors=1)

###-------------------------------------------------------------------------###


any suggestions as to why this is happening, i'm totally stumped...

-Jonathan






More information about the Twisted-Python mailing list