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

Chris Barker - NOAA Federal chris.barker at noaa.gov
Thu Jan 29 16:49:17 CET 2015

>> On Mon, Jan 26, 2015 at 05:10:44PM -0800, Chris Barker wrote:
>> That being said .. if if we want to say the primary use case is testing
>> that's fine with me -- just please not buried in unittest.TestCase
>> somewhere.
> Apart from doctest, which I think is completely inappropriate, where
> else would you put this for testing?

math would be a good place. An awful lot of testing is done outside of
the unittest module, and indeed, outside of any formal testing at all:
command line, quick if __ name__ ... Stanzas, etc.

> For testing, I think it needs to be a TestCase.assert* method.

I do think that's a good idea, but it should call the math function.
Pretty much like you have in the statistics tests. Though I'm not the
one to write that part of the PEP -- I already don't like the unittest
API ;-)


> Otherwise
> you have people writing
>    self.assertTrue(close_enough(a, b))
> I know this because that's exactly how my assertApproxEqual test
> assertion started. I'd write tests like that, they would fail, and I'd
> have no idea why. Fast forward past a few code iterations, and I had an
> assertion method which give me some useful diagnostics when it failed,
> e.g.:
> AssertionError:   20.666666666666668 != 20.66666667
>  values differ by more than tol=0 and rel=1e-12
>  -> absolute error = 3.33333360913457e-09
>  -> relative error = 1.612903358998517e-10
> --
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

More information about the Python-ideas mailing list