我正在使用nosetest工具断言python unittest
:
...
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
。这个警告来自哪里,我该如何解决?
答案 0 :(得分:7)
nose.tools
assert_*
函数仅为TestCase
方法自动创建PEP8 别名,因此assert_equals
与{{1}相同}}
但是,后者只是TestCase.assertEquals()
的别名(注意:没有尾随TestCase.assertEqual()
)。该警告旨在告诉您,您需要s
而不是TestCase.assertEquals()
而不是alias has been deprecated。
对于转换为使用TestCase.assertEqual()
的{{1}}(无跟踪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
的类似警告。