I need to unit test whether a method decorated by a Flask `route()` gets called or not.

I'd like to do this *without* modifying the original code under test, if possible, so mocking the method would suite my requirements perfectly.

Hence I am asking this *specific* question about how to mock a decorated request method (I want to stress this to try to avoid people wasting their time with less specific answers)...

Sample application `jflask.py`:

```
from flask import Flask
app = Flask(__name__)
app.config.from_object(__name__)

@app.route('/hello')           # This method represents the code under test.
def hello():                   # I want to assert that this method gets
    return 'Hello, World'      # called without modifying this code.

if __name__ == "__main__":
    app.run()

```

In the unit test I'm using `@patch()` to mock the method so I can assert it was called, but the assertion fails. I.e. the mock method doesn't get called, when I expect it to.

Sample unit test `test_hello.py`:

```
import unittest
import jflask
from unittest.mock import patch

class jTest(unittest.TestCase):
    def setUp(self):
        #jflask.app.testing = True
        self.app = jflask.app.test_client()

    @patch('jflask.hello')                # mock the hello() method
    def test_hello(self, mock_method):
        rv = self.app.get('/hello')
        mock_method.assert_called()    # this assertion fails

```

What am I doing wrong ?

---

*Background*

Some background information about the *actual* behaviour I'm trying to test
(since the above is just a condensed test case, and may not seem entirely sane by itself).

In the actual code I am unit testing, there is a `before_request()` handler
installed for the app. This gets called by Flask before each request is handled, and in
certain situations this handler has been designed to return a response value, which
causes Flask request processing to stop (in this application's case, this feature is used to centrally validate request parameters), so that the usual routed request handler will (deliberately) not get called.

My unit tests need to assert that request processing gets stopped
or continues, appropriately depending on the situation.
Hence, my test needs to mock the real request handler and assert whether
it was called or not.