I had the same issue with unit-test, testing a method that returns a dict containing floats.
assertAlmostEqual
did almost what I needed and I made it work it by comparing the values of my returned dict with the values of the expected dict using a generator comprehension:
import unittest
class TestAlmostEqual(unittest.TestCase):
def method_to_be_tested(self):
return {"A":1.035, "B":3.074, "C":5.777}
def test_almost_equal(self):
result = self.method_to_be_tested().values()
expected = {"A":1.030, "B":3.073, "C":5.779}.values()
generator = (value for value in expected)
for val in result:
self.assertAlmostEqual(val, next(generator), places=2)
Should work from python 3.6+ since dictionaries became ordered.
I'm relatively new to python so please tell me if I'm mistaken or messing something up.