title: Mock patching from/import statement in Python
body: <p>I am trying to get mock.patch to work on the following piece of sample code:</p>
  
  <pre><code>from mock import patch
  from collections import defaultdict
  
  with patch('collections.defaultdict'):
    d = defaultdict()
    print 'd:', d
  </code></pre>
  
  <p>This outputs the following:</p>
  
  <pre><code>d: defaultdict(None, {})
  </code></pre>
  
  <p>Which means that defaultdict was not patched.</p>
  
  <p>If I replace the from/import statement with a straight import statement it works:</p>
  
  <pre><code>from mock import patch
  import collections
  
  with patch('collections.defaultdict'):
   d = collections.defaultdict()
   print 'd:', d
  </code></pre>
  
  <p>Output is:</p>
  
  <pre><code>d: &lt;MagicMock name='defaultdict()' id='139953944084176'&gt;
  </code></pre>
  
  <p>Is there any way to patch a call using from/import?</p>
  
  <p>Thank you</p>