Python 3.3:使用nose.tools.assert_equals时的弃用警告
我正在使用NoTest工具断言python:Python 3.3:使用nose.tools.assert_equals时的弃用警告,python,deprecated,python-3.3,nose,python-unittest,Python,Deprecated,Python 3.3,Nose,Python Unittest,我正在使用NoTest工具断言python: 。。。 从nose.tools导入assert_equals,assert_几乎等于 类TestPolycircles(unittest.TestCase): def设置(自): 自纬度=32.074322 self.longitude=34.792081 自半径_米=100 self.number_of_顶点=36 self.vertices=polycircles.circle(纬度=self.lation, 经度=自我经度, 半径=自半径×米,
。。。
从nose.tools导入assert_equals,assert_几乎等于
类TestPolycircles(unittest.TestCase):
def设置(自):
自纬度=32.074322
self.longitude=34.792081
自半径_米=100
self.number_of_顶点=36
self.vertices=polycircles.circle(纬度=self.lation,
经度=自我经度,
半径=自半径×米,
顶点数=自身。顶点数)
def test_顶点数(自身):
“”“断言近似多边形中的顶点数
与输入匹配。”“”
断言_等于(len(self.vertices),self.number_顶点)
...
当我运行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
...
我在nose tools中找不到任何
assertEqual
。此警告来自何处,我如何修复它?nose.toolsassert.*
函数只是为TestCase
方法自动创建PEP8别名,因此assert_equals
与TestCase.assertEquals()相同
但是,后者只是TestCase.assertEqual()
(注意:没有尾随的s
)的别名。该警告旨在告诉您,您需要使用TestCase.assertEquals()
而不是TestCase.assertEqual()
作为测试用例
对于转换为使用assert_equal
(无尾随s
)的nose.tools
:
如果您使用了assert\u几乎等于
(带有尾随的s
),您也会看到使用assertAlmostEqual
的类似警告
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)