Message279456
Ran a test that I expected to pass. When the test failed, I was struck by the strange (incorrect) assertion claim when using unittest.assertAlmostEqual:
AssertionError: 32.78 != 32.775 within 2 places
Uhmm... yes it does!
I delved in, discovering that assertAlmostEquals simply calls round. So, I tried it with round, shown below:
>>> round(32.775, 2)
32.77
>>> round(32.785, 2)
32.78
>>> round(32.745, 2)
32.74
>>> round(32.746, 2)
32.75
I then looked at the documentation, to understand whether this odd behavior is indeed expected. I saw (on https://docs.python.org/3/library/functions.html#round ):
---
If two multiples are equally close, rounding is done toward the even choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2).
---
However, as you can see, this is not the behavior I'm experiencing. So, it looks like a real bug.
I am attaching the two files where I was running the unit tests, but I'm not sure you really need them.
Thank you! |
|
Date |
User |
Action |
Args |
2016-10-25 20:41:35 | lazarillo | set | recipients:
+ lazarillo |
2016-10-25 20:41:35 | lazarillo | set | messageid: <1477428095.53.0.799157743642.issue28535@psf.upfronthosting.co.za> |
2016-10-25 20:41:35 | lazarillo | link | issue28535 messages |
2016-10-25 20:41:35 | lazarillo | create | |
|