There's nothing wrong with this at all, say:
class MyClass: def __init__(self, my_dep1=None): if my_dep1 is None: self.my_dep1 = get_my_dep1() # Or potentially raise else: self.my_dep1 = my_dep1 [...]
def test_my_class(): mocked_dep1 = MagicMock() my_class = MyClass(my_dep1=mocked_dep1) [...]
There was a talk at PyCon a while back about that patterns commonly used in Java were non-existent in Python.
There's nothing wrong with this at all, say:
Then to test: