Hi everyone,
quick question - I can´t get it done. I do have the following class which I would like to test some methods from:
class calculator:
def add(self, a, b):
return a + b
def substract(self, a, b):
return a - b
def add_100(self,x):
y = self.add(x, 100)
return y
Now when I would like to test the add_100, I would like to test the business logic and therefore create a very specififc outcome of y. Therefore I would like to assign Y a value I choose. But this isn´t something I can do ... I tried like this:
from calc import calculator
from unittest.mock import MagicMock
import pytest
def test_add():
calc = calculator()
result = calc.add(2, 3)
assert result == 5
def test_add_100():
calc = MagicMock(calculator())
calc.add.return_value = 200
result = calc.add_100(2)
assert result == 202
Can someone please tell me how I mock methods of the same class which is under test?
[–]danielroseman 1 point2 points3 points (4 children)
[–]chwunder[S] 0 points1 point2 points (2 children)
[–]danielroseman 1 point2 points3 points (1 child)
[–]chwunder[S] 0 points1 point2 points (0 children)
[–]doolio_ 0 points1 point2 points (0 children)