[Twisted-Python] Naming test methods constructed with deferredGenerator - is it possible?

Mike Pelletier mike at mkp.ca
Fri Apr 28 06:57:44 MDT 2006


On Friday 28 April 2006 08:14, Marcin Kasperski wrote:
> In my trial tests I have a few test methods constructed using
> deferredGenerator idiom. Something like that:
>
>   def testSomething(self):
>        # ... do something
>        yield defer.waitForDeferred(someDeferred)
>        # ... do something
>        yield defer.waitForDeferred(otherDeferred)
>        # ... do something
>   testSomething = defer.deferredGenerator(testSomething)

> Is it possible to name the function returned by deferredGenerator
> somehow?

Shot in the dark; try adding:

    testSomething.__name__ = "testSomething"

or

    testSomething.__doc__ = "testSomething"

Not pretty, but I think it will work.  You could maybe use a util func like:

def defGen(f):
  gen = defer.deferredGenerator(f)
  gen.__name__ = f.__name__
  gen.__doc__ = f.__doc__
  return gen

Mike.




More information about the Twisted-Python mailing list