pytest: assert almost equal

后端 未结 7 1358
时光说笑
时光说笑 2020-12-24 03:55

How to do assert almost equal with py.test for floats without resorting to something like:

assert x - 0.00001 <= y <= x + 0.00001
<         


        
相关标签:
7条回答
  • 2020-12-24 04:56

    If you have access to NumPy it has great functions for floating point comparison that already do pairwise comparison with numpy.testing.

    Then you can do something like:

    numpy.testing.assert_allclose(i_return_tuple_of_two_floats(), (1.32, 2.4))
    
    0 讨论(0)
提交回复
热议问题