How do I mock part of a python constructor just for testing?
There is no need to provide a separate constructor. Mocking patches your code to replace objects with mocks. Just use the mock.patch() decorator on your test methods; it’ll pass in references to the generated mock objects. Both producer.Producer() and consumer.Consumer() are then mocked out before you create the instance: import mock class MyTest(unittest.TestCase): @mock.patch(‘producer.Producer’, autospec=True) … Read more