[Python-ideas] PEP 485: A Function for testing approximate equality

Nathaniel Smith njs at pobox.com
Fri Jan 23 18:54:53 CET 2015


On Fri, Jan 23, 2015 at 5:45 PM, Chris Angelico <rosuav at gmail.com> wrote:
> Updating the assertion to use the new function would be a matter of
> tweaking the implementation of unittest's assertAlmostEqual() to now
> call this function and assert that it returns True. The OO structure
> of unittest wouldn't be affected; just the exact definition of one
> particular assertion. I'd say that's a point worth mentioning in the
> PEP. Conceptually, this is going to do the same thing; yes, it's a
> change of definition, but obviously this won't be done in a point
> release anyway. It would make reasonable sense to sync them up.
> Alternatively, if you choose not to have that as part of the proposal,
> it would be worth adding a word or two of docs to unittest stating
> that assertAlmostEqual is not the same as is_close_to (and/or add
> "assertCloseTo" which would use it), as the existing implementation is
> all about absolute difference.

Yeah, having just taken a quick look at the source, I'd go so far as
to say assertAlmostEqual is almost totally broken. I had to read the
docs three times to work out that while it sorta sounds like it
provides relative tolerances, it actually doesn't at all -- places=3
means something like abs_tol=10**-3. Not really appropriate for
numerical work.

-n

-- 
Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org


More information about the Python-ideas mailing list