def loadTestsFromGeneratorMethod(self, generator, cls):
        """Lazy-load tests from a generator method.

        This is more complicated than loading from a generator function,
        since a generator method may yield:

        * a function
        * a bound or unbound method, or
        * a method name
        """
        # convert the unbound generator method
        # into a bound method so it can be called below
        if hasattr(generator, 'im_class'):
            cls = generator.im_class
        inst = cls()
        method = generator.__name__
        generator = getattr(inst, method)

        def generate(g=generator, c=cls):
            try:
                for test in g():
                    test_func, arg = self.parseGeneratedTest(test)
                    if not callable(test_func):
                        test_func = unbound_method(c, getattr(c, test_func))
                    if ismethod(test_func):
                        yield MethodTestCase(test_func, arg=arg, descriptor=g)
                    elif isfunction(test_func):
                        # In this case we're forcing the 'MethodTestCase'
                        # to run the inline function as its test call,
                        # but using the generator method as the 'method of
                        # record' (so no need to pass it as the descriptor)
                        yield MethodTestCase(g, test=test_func, arg=arg)
                    else:
                        yield Failure(
                            TypeError,
                            "%s is not a function or method" % test_func)
            except KeyboardInterrupt:
                raise
            except:
                exc = sys.exc_info()
                yield Failure(exc[0], exc[1], exc[2],
                              address=test_address(generator))
        return self.suiteClass(generate, context=generator, can_split=False)
def loadTestsFromGeneratorMethod ( self , generator , cls ) : if hasattr ( generator , 'im_class' ) : cls = generator . im_class inst = cls ( ) method = generator . __name__ generator = getattr ( inst , method ) def generate ( g = generator , c = cls ) : try : for test in g ( ) : test_func , arg = self . parseGeneratedTest ( test ) if not callable ( test_func ) : test_func = unbound_method ( c , getattr ( c , test_func ) ) if ismethod ( test_func ) : yield MethodTestCase ( test_func , arg = arg , descriptor = g ) elif isfunction ( test_func ) : yield MethodTestCase ( g , test = test_func , arg = arg ) else : yield Failure ( TypeError , "%s is not a function or method" % test_func ) except KeyboardInterrupt : raise except : exc = sys . exc_info ( ) yield Failure ( exc [ 0 ] , exc [ 1 ] , exc [ 2 ] , address = test_address ( generator ) ) return self . suiteClass ( generate , context = generator , can_split = False )
Lazy-load tests from a generator method.

        This is more complicated than loading from a generator function,
        since a generator method may yield:

        * a function
        * a bound or unbound method, or
        * a method name