diff --git a/delegator/delegator.py b/delegator/delegator.py index 9ea3ce8..d099243 100644 --- a/delegator/delegator.py +++ b/delegator/delegator.py @@ -24,7 +24,11 @@ def _missing(*args, **kwargs): else: _missing = getattr(target, name) - return _missing + return _missing + + raise AttributeError("'{0}' object has no attribute '{1}'".format( + self.__getobj__().__class__.__name__, name + )) def __setobj__(self, obj): raise NotImplementedError("need to define `__setobj__'") diff --git a/test/tests_delegator.py b/test/tests_delegator.py index 97fa4fb..230523a 100644 --- a/test/tests_delegator.py +++ b/test/tests_delegator.py @@ -68,3 +68,10 @@ def test_can_exec_callables_on_delegated_model(self): def test_can_exec_callables_on_itself(self): self.assertEqual(self.model_proxy.define(), "First Name, is a Person.") + + def test_raises_no_method_found_error_as_expected(self): + with self.assertRaisesRegexp( + AttributeError, + r"'FrameworkObject' object has no attribute 'this_does_not_exists'" + ): + self.model_proxy.this_does_not_exists()