Let\'s say I have a class like this.
class SomeProductionProcess(CustomCachedSingleTon):
def loaddata():
\"\"\"
Uses an iterator
To easily mock out a class method with a structured return_value, can use unittest.mock.Mock
.
from unittest.mock import Mock
mockObject = SomeProductionProcess
mockObject.loaddata = Mock(return_value=True)
EDIT:
Since you want to mock out the method with a custom implementation, you could just create a custom mock method object and swap out the original method at testing runtime.
def custom_method(*args, **kwargs):
# do custom implementation
SomeProductionProcess.loaddata = custom_method