-1

I'm using nose and I'm having troubles when using assert_in with yield.

Here's the code that causes the problem:

for row in rows:
    yield assert_in, existing_name, row[self.search_field]

The error:

Failure: ValueError (no such test method in <class 'nose.tools.trivial.Dummy'>: runTest) ... ERROR

======================================================================
ERROR: Failure: ValueError (no such test method in <class 'nose.tools.trivial.Dummy'>: runTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/maroun/.virtualenvs/ads_management/local/lib/python2.7/site-packages/nose/loader.py", line 289, in generate
    yield MethodTestCase(test_func, arg=arg, descriptor=g)
  File "/home/maroun/.virtualenvs/ads_management/local/lib/python2.7/site-packages/nose/case.py", line 345, in __init__
    self.inst = self.cls()
  File "/usr/lib/python2.7/unittest/case.py", line 191, in __init__
    (self.__class__, methodName))
ValueError: no such test method in <class 'nose.tools.trivial.Dummy'>: runTest   
----------------------------------------------------------------------

I have a workaround, simply define my own assert_in:

def assert_in(a,b):
    if not a in b:
        raise AssertionError("%r not in %r" % (a, b))

For some reason, this works. What causes the problem? I have a feeling that it's a nose bug, can anyone confirm?

Maroun
  • 94,125
  • 30
  • 188
  • 241

1 Answers1

2

According to testing-in-python mailing list:

The problem is with what you're yielding as the test callable. The "functions" in nose.tools are actually bound methods of a singleton unittest.TestCase. You can't safely yield them directly as test callables, because to nose they look like what they are, and therefore nose tries to run the test case that contains them.

Your example will work fine if you define your own assert_true:

def assert_true(arg):
    nt.assert_true(arg)

and yield that instead.

This problem seems only happens in test classes: http://asciinema.org/a/11071

falsetru
  • 357,413
  • 63
  • 732
  • 636