10
I can see two different approaches to injecting mocks into python code that I want to test:
Dependency Injection:
Allow the collaborating classes to passed into the constructor of the object under test, and pass in mock objects (and factories where necessary, like Java)
Monkey Patching:
Stub out the collaborating classes in the module under test with a mock object factory (so that constructing the collaborating classes actually creates a mock object). I don't need to allow them to be injected through the constructor or create any factories.
Both of these approaches seem to be supported by the python mocking libraries (for example, mox or mock). Which approach should I use in Python, is one of these sensible or is there a better approach?