How to mock a function decorator in Flask?
<p>I have a file named <code>myviews.py</code> that lives under a directory named <code>views</code>, which in turn in under a directory named <code>src</code> containing some views that looks like so:</p>

<pre><code>from utils import verify_refresh_token
fetch_views = Blueprint('foo', __name, url_prefix='bar')

@fetchviews.route('baz', methods=['GET'])
@verify_refresh_token
def process_request():
    return 'test'
</code></pre>

<p>Within <code>utils.py</code>, I have the verify_refresh_token function that more or less does:</p>

<pre><code>def verify_refresh_token(func):
   @wraps(func)
   def wrapper(*args, **kwargs):
      return func(*args, **kwargs)
   return wrapper
</code></pre>

<p>Within my test file, I have something like:</p>

<pre><code>from src.main import app
....
def setUp(self):
   with mock.patch('src.views.myviews.verify_refresh_token') as mock_verify_token:
      self.test_app = app.test_client(self)

def test_stuff(self):
   self.tester.post('bar/baz', data={})
</code></pre>

<p>Regardless of what I patch (changing <code>src.views.myviews.verify_refresh_token</code> to <code>src.utils.verify_refresh_token</code>, etc) the decorator still gets called and crashes my app. What is the correct way to handle mocking out this decorator? The views are added to <code>main.py</code> like so:</p>

<pre><code>app = Flask(__name__)
from views.myviews import fetchviews
app.register_blueprint(fetchviews)
</code></pre>