【问题标题】:pydev support for nose2pydev 对nose2 的支持
【发布时间】:2012-12-21 10:55:34
【问题描述】:

我已经使用 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 运行程序?如果是这样,有人知道该怎么做吗?还是我在这里遗漏了一些琐碎的事情?

【问题讨论】:

    标签: pydev nose


    【解决方案1】:

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

    您提供的错误中的这一行表明正在使用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。

    【讨论】:

      猜你喜欢
      • 2021-04-22
      • 2014-11-14
      • 2014-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-08
      • 2018-01-22
      • 2019-06-10
      相关资源
      最近更新 更多