title: Patch __call__ of a function
body: <p>I need to patch current datetime in tests. I am using this solution:</p>
  
  <pre><code>def _utcnow():
      return datetime.datetime.utcnow()
  
  
  def utcnow():
      """A proxy which can be patched in tests.
      """
      # another level of indirection, because some modules import utcnow
      return _utcnow()
  </code></pre>
  
  <p>Then in my tests I do something like:</p>
  
  <pre><code>    with mock.patch('***.utils._utcnow', return_value=***):
          ...
  </code></pre>
  
  <p>But today an idea came to me, that I could make the implementation simpler by patching <code>__call__</code> of function <code>utcnow</code> instead of having an additional <code>_utcnow</code>.</p>
  
  <p>This does not work for me:</p>
  
  <pre><code>    from ***.utils import utcnow
      with mock.patch.object(utcnow, '__call__', return_value=***):
          ...
  </code></pre>
  
  <p>How to do this elegantly?</p>