I am new to unit testing in python with MagicMock. I have the following code to assert the correct method count in python:
def methodFoo(self):
for booObject in self.booObjectList:
booObject.shooMethod()
I wish to perform an assertion call count of the method shooMethod()
in my unit test code to see if for N objects in booObjectList
it performs N calls. The above function is not my unit test code. It is a method to be tested by creating a new method test_methodFoo()
in my unit test class. How do I go about it? Thanks for you help.
Mock
objects have an attributecalled
that tracks whether a Mock has been called, and an attributecall_count
that tracks how many times they were called.Note however that you can't do something like:
since
o
is a new object each time.