B/moduleB.py
is defined as:
def text_function():
raise KeyError
text_function()
ModuleA.py
is defined as:
from B.moduleB import text_function
class a():
def __init__(self):
self.text = 'abc'
def mul(self, a, b):
print(text_function() + str(a*b))
if __name__ == "__main__":
rom = a()
rom.mul(2, 3)
This is the unit test test_module.py
:
from unittest.mock import MagicMock, patch
from moduleA import a
class TestmoduleA(unittest.TestCase):
def setUp(self):
pass
def test_mul(self):
print(a.mul)
self.assertTrue(True)
Now, is there a way to mock the text_function in B/moduleB.py while importing from moduleA such that I don't get the KeyError
?
Basically, I don't want anything to run from moduleB while testing for moduleA
Thanks in advance :)