Reputation: 35
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?
Upvotes: 1
Views: 5337
Reputation: 45039
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 class
class SomeObject(object):
def __eq__(self, other):
return self.a == other.a and self.b == other.b
Then objects which pass this test will be considered equal. By default the equality test for objects is left is right
which is only true when they are the same object, not two objects with the same values.
Upvotes: 5