This is my unittest code:
def testExtractObject(self):
self.maxDiff = None
objects = Script("compare.py").extractObjects()
self.assertListEqual([Object('ClassA',2,5,None),
Object('ClassB',1,3,None),
Object('ClassC',0,2,None)], objects)
This is the failure message:
AssertionError: Lists differ: [Object(name='ClassA', meth... != [Object(name='ClassA', meth...
First differing element 0:
Object(name='ClassA', methods=2, lines=5, description=None)
Object(name='ClassA', methods=2, lines=5, description=None)
[Object(name='ClassA', methods=2, lines=5, description=None),
Object(name='ClassB', methods=1, lines=3, description=None),
Object(name='ClassC', methods=0, lines=2, description=None)]
I cannot figure out what the difference between the lists are from this message, anyone have some insight into this?
You have to tell python how to determine whether or not two objects are equal. You do this by adding an
__eq__function to your classThen objects which pass this test will be considered equal. By default the equality test for objects is
left is rightwhich is only true when they are the same object, not two objects with the same values.