Python 3.3: DeprecationWarning when using nose.tools.assert_equals

2024/9/20 8:57:00

I am using nosetest tools for asserting a python unittest:

...
from nose.tools import assert_equals, assert_almost_equalclass TestPolycircles(unittest.TestCase):def setUp(self):self.latitude = 32.074322self.longitude = 34.792081self.radius_meters = 100self.number_of_vertices = 36self.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 polygonmatches 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?

Answer

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_equaldef test_number_of_vertices(self):"""Asserts that the number of vertices in the approximation polygonmatches 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.

https://en.xdnf.cn/q/72518.html

Related Q&A

Panel/Hvplot interaction when variable is changing

Im trying to create a dashboard with two holoviews objects: a panel pn.widgets.Select object that contains a list of xarray variables, and a hvplot object that takes the selected variable on input, lik…

asyncio matplotlib show() still freezes program

I wish to run a simulation while at the same time output its progress in a plot. Ive been looking through a lot of examples of threading and multiprocessing, but they are all pretty complex. So I thoug…

celery .delay hangs (recent, not an auth problem)

I am running Celery 2.2.4/djCelery 2.2.4, using RabbitMQ 2.1.1 as a backend. I recently brought online two new celery servers -- I had been running 2 workers across two machines with a total of ~18 thr…

Python ttk.combobox force post/open

I am trying to extend the ttk combobox class to allow autosuggestion. the code I have far works well, but I would like to get it to show the dropdown once some text has been entered without removing fo…

How to pull from the remote using dulwich?

How to do something like git pull in python dulwich library.

convert python programme to windows executable

i m trying to create windows executable from python program which has GUI . i m using following scriptfrom distutils.core import setup import py2exesetup(console=[gui.py]) it gives following errorWarni…

Must explicitly set engine if not passing in buffer or path for io in Panda

When running the following Python Panda code:xl = pd.ExcelFile(dataFileUrl)sheets = xl.sheet_namesdata = xl.parse(sheets[0])colheaders = list(data)I receive the ValueError:Must ex…

How to access the keys or values of Python GDB Value

I have a struct in GDB and want to run a script which examines this struct. In Python GDB you can easily access the struct via(gdb) python mystruct = gdb.parse_and_eval("mystruct")Now I got t…

How can I fire a Traits static event notification on a List?

I am working through the traits presentation from PyCon 2010. At about 2:30:45 the presenter starts covering trait event notifications, which allow (among other things) the ability to automatically ca…

Calculate moving average in numpy array with NaNs

I am trying to calculate the moving average in a large numpy array that contains NaNs. Currently I am using:import numpy as npdef moving_average(a,n=5):ret = np.cumsum(a,dtype=float)ret[n:] = ret[n:]-r…