title: In Python 3 how can I patch a function inside a module for unit testing?
body: <p>I have decorated methods that send timings to a hosted graphite instance they look like what is below</p>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>from util import send_timing
  
  @send_timing('login')
  def login_user():
  
      if is_user_ok():
          return True
      return False
  
  @send_timing('get_user_info')
  def get_user_info():
  
      return get_that_info()
  </code></pre>
  
  <p>I have a util file that defines the decorator</p>
  
  <p><strong>util.py</strong></p>
  
  <pre><code>def send_timing(f):
    def decorated(*args):
       make_network_connection()
       ret = f(*args)
    return decorated
  </code></pre>
  
  <p>I have some unit tests</p>
  
  <p><strong>test.py</strong></p>
  
  <pre><code>from views import *
  import unittest
  
  class TestCase(unittest.TestCase):
  
     def test_login(self):         
        self.assertTrue(login_user())
  </code></pre>
  
  <p>Now the problem is that call to <code>login_user</code>. It invokes the send_timing decorator which in turn makes a network connection. This makes my tests volatile and non-deterministic. Is there an easy way (python 3.3) to patch <code>send_timing</code> with a dummy or mock globally for all my tests?</p>