[Twisted-Python] Unit Testing in twisted 2.0

Eric Mangold teratorn at twistedmatrix.com
Tue May 17 09:55:57 EDT 2005


On Fri, 13 May 2005 05:54:58 +1000, Shawn Church <Sl_Church at sbcglobal.net>  
wrote:

> I've been following the recent thread on the problems with twisted.trial
> and since it is evidently broken I am hesitant about using it.  Instead
> I create a class that performs all of my tests and sets class attributes
> with the results.  I can then create this class once (at the module
> level) and then use the standard unittest module to check the results.
> For example (this is untested code, I'm just trying to briefly
> illustrate the approach I'm taking):
>
> class PerformTests:
>     def __init__(self):
>        self.reactorStartedResults=False
>        self.reactorStoppedResults=False
>
>        reactor.callLater(0,self.reactorStarted)
>        reactor.run()
>        self.reactorStoppedResults=True
>
>     def reactorStarted(self):
>        self.reactorStartedResults=True
>
>        # Issue another test here with .addboth(self.nextTestMethodName)
> or stop reactor:
>        reactor.stop()
>
> performTests=PerformTests()
>
> class Test(unittest.TestCase):
>     def testReactorStart(self):
>         self.assert_(performTests.self.reactorStartedResults)
>
>     def testReactorStopped(self):
>         self.assert_(performTests.self.reactorStoppedResults)
>
>    # other tests
>
>
> Should I use twisted.trial despite it's problems?  If not, is there a
> better way to implement unit testing then the approach illustrated
> above?  Any suggestions will be appreciated.

I would say just use trial. It mostly works.

-Eric

> Thanks,
>
>
> Shawn Church
> sl_church at sbcglobal.net
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>






More information about the Twisted-Python mailing list