2012-12-21 39 views
3

我一直在用PyDev成功运行鼻子测试,并且想给nose2一个尝试。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的单元测试运动员,但也许它需要ds是nose2的新选手?如果是这样,任何人都知道如何做到这一点?或者我在这里错过了一些微不足道的东西?

回答

0

这个未解决的答案是延迟了几年,但我想提供这些信息。

这条线,你提供的错误指示鼻子被用来代替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. 

如此看来nose2是PyDev的仍然不支持的,因为这日期。