I have module named square.py:
import math
class Square(object):
def __init__(radius):
self.radius = radius
def calculate_area(self):
return math.sqrt(self.radius) * math.pi
And I have written test for this using py.test:
from square import Square
def test_mocking_class_methods(monkeypatch):
monkeypatch.setattr('test_class_pytest.Square.calculate_area', lambda: 1)
assert Square.calculate_area() == 1
Running this test in python 2 gives me the following output:
> assert Square.calculate_area() == 1
E TypeError: unbound method <lambda>() must be called with Square instance as first argument (got nothing instead)
But the same test in python 3 passes. Do you know why is that and how can I fix this test to work with python 2?