3

我一直在用 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中选择了nose作为单元测试运行器,但也许它需要一个新的nose2运行器?如果是这样,有人知道该怎么做吗?还是我在这里遗漏了一些微不足道的东西?

4

1 回答 1

0

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

您提供的错误中的这一行表明正在使用nose 而不是nose2,因为nose2 是一个可通过pip 安装的单独包:

File "/usr/local/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest

我还尝试nose2在 pydev 中使用,从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。

于 2014-12-15T15:26:42.800 回答