[Twisted-Python] using yield in unittest.TestCase
maitland at vanu.com
maitland at vanu.com
Thu May 19 13:12:58 MDT 2005
Jp-
That makes sense. I'm using flow, so maybe I see if I can port over
to deferredGenerators.
Thanks,
-Maitland
On Thu, May 19, 2005 at 06:43:30PM +0000, Jp Calderone wrote:
> On Thu, 19 May 2005 13:56:31 -0400, maitland at vanu.com wrote:
> >Hi all-
> >
> >I've been trying to unit test some code that uses a lot of generators
> >and Callbacks, so I would like to be able yield my Callbacks and check
> >them out. However, whenever I stick a yield in my test case (in a
> >subclass of trial.unittest.TestCase), the test automatically passes
> >and, as far as I can tell, doesn't actually get evaluated at all.
> >
> >Is this a known issue? Does anybody know of a way I can work around
> >it?
> >
>
> As you're probably aware, putting a yield into a function definition
> turns the function into a generator function. As you are also probably
> aware, calling a generator function returns a generator, but doesn't
> execute any code in the generator function: only when the generator is
> iterated is the generator function executed.
>
>
> So trial calls your test method and gets back a generator. It doesn't
> know a thing about generators. So it ignores it and moves on. The test
> passes because it didn't raise an exception.
>
> If you're trying to use the new Deferred generator feature to use use a
> generator function to manipulate a Deferred, you need to decorate your
> test method with deferredGenerator:
>
> def testFoo(self):
> ...
> testFoo = deferredGenerator(testFoo)
>
> If you're trying to use flow, you probably shouldn't. It's unclear to
> me what the path to support flow in trial is.
>
> If you're trying to do something else... I'm confused.
>
> Jp
>
> _______________________________________________
> 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