Is this the correct approach when creating a mock which should track the order in which methods are called for a given class?
class MockFoo():
def __init__(self):
self.calledMethods = []
def medthod1(self):
self.calledMethods.append(self.medthod1.__name__)
def medthod2(self):
self.calledMethods.append(self.medthod2.__name__)
self.assertEqual(len(foo.calledMethods),2)
self.assertEqual(foo.calledMethods[0],MockFoo.title.__name__)
Can I save something better than __name__?
You can certainly do this, but consider the following two approaches and decide which is the more readable:
“Readability counts.”