[Python-ideas] PEP 485: A Function for testing approximate equality
abarnert at yahoo.com
Mon Jan 26 02:39:00 CET 2015
On Jan 25, 2015, at 17:21, Chris Barker <chris.barker at noaa.gov> wrote:
>> Unfortunately, I don't think we can change assertAlmostEqual. If we
>> change the implementation, tests which were passing may fail, and tests
>> which were failing may pass.
> Agreed -- would have thought that was off the table.
If assertAlmostEqual is primarily intended for float comparisons, and it really is misleadingly bad for that use, I'd think the right answer is to prove a new, better method under a different name, then deprecate the old one. That means old tests continue to work, but new tests stop being misled into testing the wrong thing, and if you're a few people will even think to redo old tests (and, presumably, discover long-standing bugs--otherwise either their tests cases are no good in the first place, or it's really not misleadingly bad, right?), which seems to be the best outcome you can reasonably hope for.
That would imply that assertCloseTo should include the same sequence behavior as assertAlmostEqual, not just assertTrue(close_to), so it really is a drop-in replacement for most users.
I suppose making assertAlmostEqual take an optional almost-equality function that defaults to the existing behavior, then deprecating calling it with the default, would have the same effect, but it seems clumsier in the long run.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas