0
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?

Abhishek Kumar
  • 729
  • 6
  • 20

1 Answers1

0

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:

https://docs.python.org/3/library/unittest.mock.html

Kaan Ant
  • 36
  • 2