2012-12-21 69 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的仍然不支持的,因爲這日期。