title: Python: mock or patch a class with code executed in class initialization
body: <p>I have two files, says 'example.py' and 'test.py'</p>
  <p>The example.py is like:</p>
  <pre><code>  class Example(object):
      print('hello world')
  
      def greeting(self, words):
          print(words)
  </code></pre>
  <p>and example.py is imported in test.py :</p>
  <pre><code>import example
  </code></pre>
  <p>This will cause code 'print('hello world') to be executed.</p>
  <p>Is there a way in unittest.mock to mock() or patch() class Example to stop <code>print('hello world')</code> being executed but still to keep method <code>greeting()</code> working?</p>