我正在使用nosetest工具来断言pythonunittest https://docs.python.org/3.3/library/unittest.html:
...
from nose.tools import assert_equals, assert_almost_equal
class TestPolycircles(unittest.TestCase):
def setUp(self):
self.latitude = 32.074322
self.longitude = 34.792081
self.radius_meters = 100
self.number_of_vertices = 36
self.vertices = polycircles.circle(latitude=self.latitude,
longitude=self.longitude,
radius=self.radius_meters,
number_of_vertices=self.number_of_vertices)
def test_number_of_vertices(self):
"""Asserts that the number of vertices in the approximation polygon
matches the input."""
assert_equals(len(self.vertices), self.number_of_vertices)
...
当我跑步时python setup.py test
,我收到弃用警告:
...
Asserts that the number of vertices in the approximation polygon ...
/Users/adamatan/personal/polycircles/polycircles/test/test_polycircles.py:22:
DeprecationWarning: Please use assertEqual instead.
assert_equals(len(self.vertices), self.number_of_vertices)
ok
...
我找不到任何assertEqual
在鼻子工具中。这个警告来自哪里,我该如何解决它?
The nose.tools
assert_*
函数只是自动创建的 PEP8aliases为了TestCase
方法,所以assert_equals
是相同的TestCase.assertEquals()
.
然而,后者只是曾经alias for TestCase.assertEqual()
(note: 没有尾随s
)。该警告旨在告诉您,而不是TestCase.assertEquals()
你需要使用TestCase.assertEqual()
as the 别名已被弃用 http://bugs.python.org/issue9424.
For nose.tools
这转化为使用assert_equal
(没有尾随s
):
from nose.tools import assert_equal, assert_almost_equal
def test_number_of_vertices(self):
"""Asserts that the number of vertices in the approximation polygon
matches the input."""
assert_equal(len(self.vertices), self.number_of_vertices)
你用过吗assert_almost_equals
(带有尾随s
),你会看到类似的警告来使用assertAlmostEqual
,还有。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)