我正在使用nose,而assert_in
与yield
一起使用时遇到了麻烦。
以下是导致问题的代码:
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))
出于某种原因,这个有效。是什么原因造成的?我觉得这是一个鼻子虫,任何人都可以确认吗?
答案 0 :(得分:2)
根据testing-in-python mailing list:
问题在于你可以作为测试可调用的东西。该 nose.tools中的“functions”实际上是单例的绑定方法 unittest.TestCase生成。你不能直接安全地将它们作为测试产生 callables,因为他们看起来像他们的鼻子,因此 nose试图运行包含它们的测试用例。
如果您定义自己的assert_true,那么您的示例将正常工作:
def assert_true(arg): nt.assert_true(arg)
而是屈服于此。
此问题似乎只发生在测试类中:http://asciinema.org/a/11071