Title: How to mock imported function in a Flask Blueprint
Tags: python;unit-testing;flask;mocking
Question: I have a Flask Blueprint that imports a function from the parent Flask module as such:
from app_name.utils import try_ad_connection
I am trying to mock/patch try_ad_connection but I don't know what my target should be in the patch decorator as the Blueprint is not a module, so targeting app_name.blueprint_name.try_ad_connection does not seem to work.
If I change my import to the whole utils file and call try_ad_connection by app_name.utils.try_ad_connection, I can patch it by using app_name.utils.try_ad_connection as the target, but I'd like to avoid importing the whole file to just use one function.
Comment: This requires more content to be able to act on it. I fixed the markup, but I still think it should be closed without code examples.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:06/11/16', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<python><unit-testing><flask><mocking>', 'Title': 'How to mock imported function in a Flask Blueprint', 'ViewCount': 328, 'id': 37766533, 'user_AboutMe': None, 'user_AccountId': 5923298.0, 'user_DisplayName': 'Cosmo-Kramer', 'user_Reputation': 121.0, 'user_Views': 1.0, 'user_id': 4660038.0}}