I am trying to use Python's mock
library in my unit testing but I am seeing inconsistent results depending on how I import the target that I am trying to patch. I would expect that both of these print statements should return False
but it appears that only the second statement returns False
:
from requests import get
import requests
with mock.patch('requests.get') as get_mock:
get_mock.return_value.ok = False
print get('http://asdf.com').ok
print requests.get('http://asdf.com').ok