I am using nosetest tools for asserting a 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)
...
When I run python setup.py test
, I get a deprecation warning:
...
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
...
I could not find any assertEqual
in nose tools. Where is this warning coming from, and how can I fix it?
The nose.tools
assert_*
functions are just automatically created PEP8 aliases for the TestCase
methods, so assert_equals
is the same as TestCase.assertEquals()
.
However, the latter was only ever an alias for TestCase.assertEqual()
(note: no trailing s
). The warning is meant to tell you that instead of TestCase.assertEquals()
you need to use TestCase.assertEqual()
as the alias has been deprecated.
For nose.tools
that translates into using assert_equal
(no trailing 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)
Had you used assert_almost_equals
(with trailing s
), you'd have seen a similar warning to use assertAlmostEqual
, as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With