I have code like this:
a.py
from app.cache import Cache
my_cache = Cache(cache_prefix='xxxxx')
b.py
from a import my_cache
class MyApp:
def run_app():
my_cache.get(1,2)
test_b.py
from mock import Mock, patch
import b
mock_my_cache_get= Mock(b.my_cache.get)
class MyTests():
@patch('b.my_cache.get', mock_my_cache_get)
def test_cache(self):
b.MyApp().run_app()
mock_my_cache_get.assert_called_with(1,2)
As you can see above, I am trying to write a unit test where I mock the get method of the class instance of Cache. However, when I try to assert that this mocked method is called with the specified arguments, I get an error saying that call is not found. Which, as iis obvious that is is.
You can leave unchanged files
a.pyandb.py, but you have to change yourtest_b.pyas following:run_app()method.import binstruction.EDIT I have replicated your code in my system and the structure of my folder is:
Following I report how I have executed the test in my system and the output of the execution:
It is strange what happens in your system.