I want to write test for Subclass while mocking Base as Base comes from an external library. How can I mock it given that we modify all callables in base class.
class SubClass(Base):
def __init__(self, *args, **argv):
super().__init__(*args, **argv)
for attr_name in Base.__dict__:
attr = getattr(self, attr_name)
if callable(attr):
setattr(self, attr_name, functools.partial(__class__.sanity_check, attr))
@classmethod
def sanity_check(func):
txt = func()
if 'banned_word' in txt:
raise Exception('Device has banned word on it!')
return txt