nsigustavo/ludibrio — Issue #8: No longer possible to stub an exception raise in latest version
Author: sk-
Created: 2012-02-11 03:42:04+00:00
State: open

In the latest version is no longer possible to raise an exception from a Stub. Version 3.0 was working just fine. The problem is that the line checking is the returned value was an instance of exception was deleted from the method _expectation_value.

See the attached test below:

import os
from unittest import TestCase

from ludibrio import Stub, Mock

class TestRaiseException(TestCase):
def test_stub_raise_exception(self):
with Stub() as exists:
exists() >> Exception('exist raised a mocked exception from stub')
with self.assertRaises(Exception):
exists()
exists.restore_import()

def test_mock_rasise_exception(self):
with Mock() as exists:
exists() >> Exception('exist raised a mocked exception from stub')
with self.assertRaises(Exception):
exists()
exists.validate()