I am doing some unit testing and at some point I need to mock a super call to throw an error, for example:
@classmethod
def myfunc(cls, *args, **kwargs)
try:
super(MyClass, cls).my_function(args, kwargs)
except MyException as e:
#...
I am using the mocker library to mock my objects in general but I haven’t found a way to mock this.
I found a way, sort of hacky but it works, I’ll explain with my example, this is based on this response so thanks @kindall:
so essentially what I do is check if the
supercall is from the class I want to mock, else just do a normalsuper.Hope this helps someone 🙂