Below is my source code
#src.py
from common.configs import MANDATORY_FIELDS
def check_mf():
if set(MANDATORY_FIELDS).issubset(['a','b','c']):
return True
else:
raise Exception("Error in mandatory fields")
And here is my test code
#test_src.py
from unittest import TestCase, main, mock
from src import check_mf
class TestMailSenderUtil(TestCase):
def test_method(self):
with mock.patch('src.MANDATORY_FIELDS') as mocked_mf:
mocked_mf.return_value = ['a','b','c','d']
self.assertRaises(ValidationException, check_mf)
when i run this code the test is not passing. It throws an error saying that
AssertionError: ValidationException not raised by check_mf
Why do i get this error? FYI, when i try to print MANDATORY_FIELDS in src.py file while running unittesting i get this
<MagicMock name='MANDATORY_FIELDS' id='139766761401144'>
Why the mocking is not working here?