[TIP] Generator methods and nose: a bit lost...

Fernando Perez fperez.net at gmail.com
Tue Apr 21 14:53:34 PDT 2009


Hi all,

I've been reading the nose docs about generator methods, and as far as
I can make out from the information provided, there's nothing special
required of them in the signature or anything else.  So I'm stumped as
to why this particular bit of code doesn't work:

###
"""Simple example of test generators in nose"""

import nose.tools as nt

class Test1(object):

    # A test generator - no docstring so nose reports arguments
    def testgen(self):
        for i in range(2):
            yield nt.assert_true,True


# A test generator - no docstring so nose reports arguments
def testgen():
    for i in range(2):
        yield nt.assert_true,True

### EOF

The tesgen() function at the end works as expected, but the one that's
a method fails:

uqbar[python]> nosetests -vvs test_nosegen.py
ERROR
test_nosegen.testgen(True,) ... ok
test_nosegen.testgen(True,) ... ok

======================================================================
ERROR: test suite
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/fperez/usr/local/lib/python2.5/site-packages/nose-0.10.4-py2.5.egg/nose/suite.py",
line 154, in run
    self.setUp()
  File "/home/fperez/usr/local/lib/python2.5/site-packages/nose-0.10.4-py2.5.egg/nose/suite.py",
line 180, in setUp
    if not self:
  File "/home/fperez/usr/local/lib/python2.5/site-packages/nose-0.10.4-py2.5.egg/nose/suite.py",
line 65, in __nonzero__
    test = self.test_generator.next()
  File "/home/fperez/usr/local/lib/python2.5/site-packages/nose-0.10.4-py2.5.egg/nose/loader.py",
line 257, in generate
    yield MethodTestCase(test_func, arg=arg, descriptor=g)
  File "/home/fperez/usr/local/lib/python2.5/site-packages/nose-0.10.4-py2.5.egg/nose/case.py",
line 327, in __init__
    self.inst = self.cls()
  File "/usr/lib/python2.5/unittest.py", line 209, in __init__
    (self.__class__, methodName)
ValueError: no such test method in <class 'nose.tools.Dummy'>: runTest

----------------------------------------------------------------------
Ran 2 tests in 0.002s

FAILED (errors=1)



This is running nose 0.10.4 on Ubuntu 64 bits.  I'll be happy to
provide any further details...

Thanks for any help!

f



More information about the testing-in-python mailing list