I'm familiar with other mocking libraries in other languages such as Mockito in Java, but Python's mock
library confuses the life out of me.
I have the following class which I would like to test.
class MyClassUnderTest(object):
def submethod(self, *args):
do_dangerous_things()
def main_method(self):
self.submethod("Nothing.")
In my tests, I'd like to make sure that the submethod
was called when main_method
was executed and that it was called with the right arguments. I don't want submethod
to run, as it does dangerous things.
I'm entirely unsure as to how to get started with this. Mock's documentation is incredibly hard to understand and I'm not sure what to even mock or how to mock it.
How can I mock the submethod
function, while leaving the functionality in main_method
alone?