2014-07-27 156 views
-1

我使用nose和我使用assert_inyield時遇到麻煩。使用yield'與assert_in鼻子時出錯

下面是導致該問題的代碼:

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

錯誤:

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 
---------------------------------------------------------------------- 

我有一種變通方法,簡單地定義自己的assert_in

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

出於某種原因,這作品。是什麼導致了問題?我有一種感覺,這是一個鼻子的bug,任何人都可以證實?

回答

2

根據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.

這個問題似乎只發生在測試類:http://asciinema.org/a/11071