[Twisted-Python] unit testing question: twisted with tk
Russell E. Owen
rowen at uw.edu
Wed Jul 18 14:26:37 EDT 2012
In article <5006FC68.8050307 at itamarst.org>,
Itamar Turner-Trauring <itamar at itamarst.org> wrote:
> 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).
I put tksupport.install(root) in the setUp and tksupport.uninstall() in
the tearDown and it worked perfectly.
Thank you very much. I'm thrilled to be able to run these unit tests.
More information about the Twisted-Python