samedi 18 avril 2020

Mock all instances of class method

If I have:

class A:
    def method():
        pass

class B(A):
    def method():
        pass

I want to be able to do mocker.patch.object(A, 'method') and then when I call b.method() I want it to use the mock. I know I can do mocker.patch.object(B, 'method') but I wanted to see if there is a way to mock the base class method and have it translate to any derived class that overrides that method. AKA if I mock method is class A, I want it to also mock method in class B. Is this possible?

Aucun commentaire:

Enregistrer un commentaire