In lib/thing.py:
class Class(object):
def class_function1(self):
In app/thing.py:
def function2(class_object):
class_object.class_function1()
In test/test_thing.py, I want to patch lib.thing.Class.class_function1 when function2 is called with a mocked Class() object to raise an AttributeError which should just perc up to test_function2 unimpeded. Something like this (which doesn't work):
def test_function2(self):
mocked_class = mock.MagicMock(name="class", spec_set=lib.thing.Class)
with assertRaises(AttributeError):
with patch ('lib.thing.Class.class_function1', side_effect=AttributeError):
function2(mocked_class)
mocked_class.class_function1.side_effect = AttributeErrorraises theAttributeErrorcorrectly whenclass_function1gets hit infunction2, butassertRaisesdoesn't acknowledge it. Hm. One step closer or one step sideways ...