I'm having issues raising an exception from a function in my test:
### Implemetation
def MethodToTest():
myVar = StdObject()
try:
myVar.raiseError() # <--- here
return True
except Exception as e:
# ... code to test
return False
### Test file
@patch('stdLib.StdObject', autospec=True)
def test_MethodeToTest(self, mockedObjectConstructor):
mockedObj = mockedObjectConstructor.return_value
mockedObj.raiseError.side_effect = Exception('Test') # <--- do not work
ret = MethodToTest()
assert ret is False
I would like to raiseError()
function to raise an error.
I found several examples on SO, but none that matched my need.