How to do assert almost equal
with py.test for floats without resorting to something like:
assert x - 0.00001 <= y <= x + 0.00001
More specifically it will be useful to know a neat solution for quickly compare pairs of float, without unpacking them:
assert (1.32, 2.4) == i_return_tuple_of_two_floats()
Best Answer
I noticed that this question specifically asked about py.test. py.test 3.0 includes an
approx()
function (well, really class) that is very useful for this purpose.The documentation is here.