title: Python: setting default side_effect with create_autospec on class instance
body: <p>I am trying to use <code>side_effect</code> with <code>unittest.mock.create_autospec</code> on class to set default instance call behavior to <code>raise NotImplementedError</code>.</p>
  <p>The problem I am facing is:</p>
  <ul>
  <li>I do not want exception to be raise on class <code>__init__</code>.</li>
  <li>I do not want to set explicitly all my methods side effect.</li>
  <li>I want to use a <code>pytest.fixture</code> in order to make my mock reusable through various tests.</li>
  </ul>
  <p>Here a code sample of what I am trying to achieve.</p>
  <pre class="lang-py prettyprint-override"><code># module.py
  
  class MyClass:
      def __init__(self, value):
          self.value = value
  
      def compute(self):
          return self.value
  
  
  def foo():
      instance = MyClass(42)
      return instance.compute()
  </code></pre>
  <pre class="lang-py prettyprint-override"><code># test_module.py
  
  from unittest.mock import create_autospec
  import module
  import pytest
  
  
  @pytest.fixture(autouse=True)
  def my_class(monkeypatch):
      # Help me HERE to set side_effect, bellow tests will not work with this settings.
      spec_cls = create_autospec(module.MyClass, side_effect=NotImplementedError)
  
      monkeypatch.setattr(module, &quot;MyClass&quot;, spec_cls)
  
      return spec_cls(&quot;&lt;whatever&gt;&quot;)
  
  
  def test_foo():
      with pytest.raises(NotImplementedError):
          module.foo()
  
  
  def test_bar(my_class):
      my_class.compute.return_value = 24
      assert module.foo() == 24
  </code></pre>