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

Paul Moore p.f.moore at gmail.com
Thu Jan 29 15:13:55 CET 2015


On 29 January 2015 at 13:34, Steven D'Aprano <steve at pearwood.info> wrote:
> For testing, I think it needs to be a TestCase.assert* method. Otherwise
> you have people writing
>
>     self.assertTrue(close_enough(a, b))

The only downside is that this doesn't consider other test frameworks
like nose and py.test. For those frameworks, you need a standalone
function. *If* the intention is to expose a function that people can
use for testing, I think it needs to be a standalone close_enough
function plus a unittest assert method that uses that function.

But I'm fairly sure by now that Guido's right and this should just be
a recipe. I can write my own close_enough function now, with the
information from this thread. The only bit I'd struggle over is what
tolerance to use, and it doesn't look like anyone has a particularly
good universal answer for that :-)

Paul


More information about the Python-ideas mailing list