[Twisted-Python] using yield in unittest.TestCase

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? Thanks, -Maitland

On Thu, 19 May 2005 13:56:31 -0400, maitland@vanu.com wrote:
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

On Thu, 19 May 2005 13:56:31 -0400, maitland@vanu.com wrote:
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
participants (2)
-
Jp Calderone
-
maitland@vanu.com