Halst Halst - 4 months ago 184x
Python Question

pytest: assert almost equal

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()


You will have to specify what is "almost" for you:

assert abs(x-y) < 0.0001

and although its a completely different question:

assert all([i==j for i,j in zip(tuple1,tuple2)])