我一直在使用PyDev成功运行鼻子测试,并想尝试使用nose2。
所以我用
安装了它pip install nose2
将示例代码从http://nose2.info/复制/粘贴到名为“test_script_with_nose2”的新模块中:
from nose2.compat import unittest
from nose2.tools import params
def tests_can_be_functions():
assert True
def tests_can_be_generators():
def check(val):
assert val == val, "Identity failure!"
for i in range(1, 4):
yield check, i
@params(1, 2, 3)
def tests_can_take_parameters(p):
assert p < 4, "How'd that get here?"
class TestsCanBeUnittestTestCases(unittest.TestCase):
def setUp(self):
self.x = 1
def test_one(self):
self.assertEqual(self.x, 1)
class TestsCanBePlainClasses(object):
def setUp(self):
self.me_too = 1
def test(self):
assert self.me_too == 1, "Not me too?"
但是我收到了这个错误
======================================================================
ERROR: test_script_with_nose2.tests_can_take_parameters
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
TypeError: tests_can_take_parameters() takes exactly 1 argument (0 given)
----------------------------------------------------------------------
Ran 7 tests in 0.014s
FAILED (errors=1)
我选择了作为pydev中的单元测试运行器的鼻子,但也许它需要一个新的nose2运动员?如果是这样,谁知道怎么做?或者我在这里错过了一些小事?
答案 0 :(得分:0)
这个未解决的答案延迟了几年,但我想提供这些信息。
您提供的错误中的这一行表示正在使用nose而不是nose2,因为nose2是一个可以通过pip安装的独立包:
File "/usr/local/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
我还尝试在pydev中使用nose2
,从nose
升级。我已卸载nose
并已安装nose2
,然后尝试运行您提供的测试代码,但导入nose2
时失败,而不是您提供的错误。
ImportError: No module named nose2.compat
然后,我尝试了一些我已经拥有的单元测试,但得到了以下信息:
Warning: Could not import the test runner: --nose-params. Running with the default pydev unittest runner instead.
因此截至此日期,pydev似乎仍然不支持nose2。