After upgrading from Mock 3.0.5 to 4.0.0, my unit tests fail. I'm guessing patch is no longer working on flask.g but I haven't been able to find a workaround.
from mock import patch
import flask
def some_function():
flask.g.somevariable = True
return flask.g.somevariable
@patch('flask.g')
def test_some_function(mock_flask_global):
assert some_function()
Output:
name = 'g'
def _lookup_app_object(name):
top = _app_ctx_stack.top
if top is None:
> raise RuntimeError(_app_ctx_err_msg)
E RuntimeError: Working outside of application context.
E
E This typically means that you attempted to use functionality that needed
E to interface with the current application object in some way. To solve
E this, set up an application context with app.app_context(). See the
E documentation for more information.
venv/lib/python3.6/site-packages/flask/globals.py:45: RuntimeError
========================================================================================================== short test summary info ===========================================================================================================
FAILED temp_test.py::test_some_function - RuntimeError: Working outside of application context.
This worked properly in mock 3.0.5