课堂内的鼻子测试发生器
是否可以在自定义类中运行鼻子测试生成器?我正在尝试将 示例 转换为基于简单类的版本:
file: trial.py
>>>>>>>>>>>>>>
class ATest():
def test_evens(self):
for i in range(0, 5):
yield self.check_even, i, i * 3
def check_even(self, n, nn):
assert n % 2 == 0 or nn % 2 == 0
这导致
$ nosetests -v trial.py
----------------------------------------------------------------------
Ran 0 tests in 0.000s
我查看了变更日志,并相信这应该可以从版本 0.9.0a1。
我哪里出错了?
Is it possible to run nose test generators inside custom classes? I am trying to convert the example into a simple class based version:
file: trial.py
>>>>>>>>>>>>>>
class ATest():
def test_evens(self):
for i in range(0, 5):
yield self.check_even, i, i * 3
def check_even(self, n, nn):
assert n % 2 == 0 or nn % 2 == 0
That results in
$ nosetests -v trial.py
----------------------------------------------------------------------
Ran 0 tests in 0.000s
I had a look through the changelog and believe that this should work since version 0.9.0a1.
Where am I going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信你必须子类化unittest.TestCase
I believe you have to subclass unittest.TestCase
解决方案是一个不太预期的解决方案:为了让nosetests发现生成器方法,不要从
unittest.TestCase
子类化。使用nosetests 1.1.3(最新来自GitHub)的代码:另外,使用
TestA
而不是ATest
。The solution is the less expected one: do NOT subclass from
unittest.TestCase
in order to have nosetests discover the generator method. Code working with nosetests 1.1.3 (latest from GitHub):Also, use
TestA
instead ofATest
.