我正在使用鼻子测试工具来声明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
在鼻工具中找不到任何东西。该警告从何而来,我该如何解决?
这些nose.tools
assert_*
函数只是为方法自动创建的PEP8别名TestCase
,因此assert_equals
与相同TestCase.assertEquals()
。
然而,后者是有史以来唯一一个别名为TestCase.assertEqual()
(注:没有结尾s
)。该警告旨在告诉您,由于别名已被弃用,因此TestCase.assertEquals()
您无需使用TestCase.assertEqual()
它。
对于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
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句