[Twisted-Python] unit testing question: twisted with tk

Itamar Turner-Trauring itamar at itamarst.org
Wed Jul 18 12:11:52 MDT 2012


On 07/18/2012 01:01 PM, Russell E. Owen wrote:
> I have a bit of code that combines twisted with Tkinter
> and now I'd like to write some unittests for it.
>
> I can't seem to figure out how to get TwistedTrial to handle this case.
> I've written a unit test like this:
>
> from twisted.trial import unittest
> from twisted.internet.defer import Deferred
> import twisted.internet.tksupport
> root = Tkinter.Tk()
> twisted.internet.tksupport.install(root)
> from twisted.internet import reactor
>
> class TestTkSocket(unittest.TestCase):
>      def test...(...):
>          ....
>
> the one test so far returns a deferred and calls errback on that
> deferred if the test fails, and callback if it succeeds. When I run the
> unit test with trial I get this error error:
> twisted.trial.util.DirtyReactorAggregateError

The problem is that setting up tk support involves a repeatedly 
scheduled event, which means it's in the reactor causing that warning. 
Make sure you call tksupport.uninstall() at the end of each test, by 
either putting in tearDown or doing self.addCleanup(tksupport.uninstall).




More information about the Twisted-Python mailing list