I have the following files -
summer.py
def sum(a, b):
return a+b
base.py
class Base():
def work(self, a, b):
self.add(a, b)
calculator.py
from summer import sum
from base import Base
class Calculator(Base):
def work(self, a, b):
super().work(a, b)
def add(self, a, b):
return sum(a, b)
test_calculator.py
from unittest import mock
from calculator import Calculator
@mock.patch('calculator.sum')
def test_calc(mock_sum):
a = 5
b = 10
mock_sum.return_value = 0
Calculator().work(a, b)
mock_sum.assert_called_once()
However, when I run test_calculator.py
I get an AssertionError
as follows -
AssertionError: Expected 'mock_sum' to have been called once. Called 0 times.
What is the correct way to mock sum()
?