sách gpt4 ai đã đi

pydev hỗ trợ nose2

In lại 作者:行者123 更新时间:2023-12-05 01:15:47 27 4
mua khóa gpt4 Nike

我一直在使用 PyDev 成功运行 nose 测试,并想试试 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
-----------------------------------------------------------------------------------
Theo dõi (cuộc gọi gần đây nhất là cuộc gọi cuối cùng):
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 运行器?如果是这样,有人知道该怎么做吗?还是我在这里遗漏了一些微不足道的东西?

1 Câu trả lời

这个 Unresolved 答案被推迟了几年,但我想提供这些信息。

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

关于pydev 支持 nose2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13988813/

27 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com