I have a main class from which I am writing the unit test. The main class calls the helper class methods which consume a lot of CPU cycle. I want to mock helper class methods so that whenever I call main class methods - it calls the mock helper methods instead of the real ones.
I want the code inside the main class method to execute - just that when it comes to calling the method from helper class - it calls the mock method.
Here's the structure.
MainClass.py
import helperClass as helper
Class MainClass:
def testMethod(self):
helper.methodWhichIwantToMock()
helperClass.py just has one method
def methodWhichIwantToMock():
print "I love CPU cycles"
I read that I could spy on the MainClass in a way that when certain dependent methods are called within MainClass - I can mock them and return what I want. But in this case the methods I want to mock are in different class from the one I am testing.
Aucun commentaire:
Enregistrer un commentaire