I use Python\'s unittest
module and want to check if two complex data structures are equal. The objects can be lists of dicts with all sorts of values: numbers,
I would define my own assertNumpyArraysEqual() method that explicitly makes the comparison that you want to use. That way, your production code is unchanged but you can still make reasonable assertions in your unit tests. Make sure to define it in a module that includes __unittest = True
so that it will not be included in stack traces:
import numpy
__unittest = True
def assertNumpyArraysEqual(self, other):
if self.shape != other.shape:
raise AssertionError("Shapes don't match")
if not numpy.allclose(self, other)
raise AssertionError("Elements don't match!")