class C:
def f():
calls g
def g():
# Do something
How can I mock g to test f in a testing module which imports class C?
class C:
def f():
calls g
def g():
# Do something
How can I mock g to test f in a testing module which imports class C?
u can Mock that function with using path object like that;
with patch.object(C, 'g', MagicMock(return_value='something')):
c.f()
with that way when your code calls g function, it returned mocked response
Note: use should import patch before use it
You can find detailed information from link below: