Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.3: DeprecationWarning when using nose.tools.assert_equals

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?

like image 664
Adam Matan Avatar asked Apr 13 '14 07:04

Adam Matan


1 Answers

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.

like image 123
Martijn Pieters Avatar answered Oct 24 '22 10:10

Martijn Pieters