Here is the proj structure that I have -
src/
package1/
__init__.py
file1.py # has the method -> _method_name
tests/
__init__.py
test_file1.py
I am using unittest to test my code. I want to mock a method in a package1 and run my tests. Here is what i am doing to mock that method -
with unittest.mock.patch('package1.file1._method_name') as method_name_mock:
This should create a MagicMock for the method name. When i start debugging, it invokes the real method which i don't want.
I am checking if the mock was called twice which it should but somehow it fails since the real method gets called -
assert method_name_mock.call_count == 2
What am I doing wrong?