My project structure:
├── core
| └── service
| └── file.py
└── tests
└── test_file.py
I have a function fun that uses a class method.
file.py
from another_module import myClass
cls_instance=myClass()
def fun():
return cls_instance.request()
And I want to test the function fun by patch as showed below:
test_file.py
from core.service.file import fun
class TestCase(unittest.TestCase):
@patch("core.service.file.cls_instance")
def setUp(self, mock):
self.mock = mock.return_value
def test_fun(self):
self.mock.request.return_value = 1
resp=fun()
self.assertEqual(resp, 1)
Test Failed with the message:
Expected : None
Actual : 1
What am I doing wrong here?