My code is organized as several independent classes. Each dependency is injected by a setter, so in the end I create instances of classes
C, set their parameters and inject them to class
Now I want to test class
A in isolation, so my first intuition is to create mocks for
C. My problem is that methods from
C are called multiple times with different parameters and return different results. How can I mock that?
b = B() b.set_param1(value1) b.set_param1(value2) c = C() c.set_param1(value1) c.set_param1(value2) a = A() a.set_b(b) a.set_c(c) a.run(): X = self.get_b().method1(x) # should return 1 Y = self.get_b().method2(y) #s hould return 2 Z = self.get_c().method1(z) # should return a complicated dataframe W = self.get_c().method2(w)# should return yet another complicated dataframe # process W X Y Z ...
Everything I read on mocking in python is limited to very simple examples where mocking can happen locally.
I know I can set a sequence of return values, but this is limited to a single method and is not future proof if the code logic changes.
Is it even possible or correct to test such a hierarchy?