summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Niemeyer <gustavo@niemeyer.net>2009-02-13 12:10:28 +0000
committerGustavo Niemeyer <gustavo@niemeyer.net>2009-02-13 12:10:28 +0000
commita9b44545edaae14ea4656181a93a98cfaad8310c (patch)
tree26db48abcb6c12aece30c3fef53c6edc92e37b29
parent8a4227cfcc32fed041462ebf6031d722bb0c39a1 (diff)
parent44c1f801a3068647673c7e827827bab7cc72264c (diff)
downloadmocker-a9b44545edaae14ea4656181a93a98cfaad8310c.tar.gz
Merged 328990-mocker-hides-exception branch from Duncan McGreggor. This
ensures that the raised AttributeError exception on a patched object actually exposes the real problem rather than an internal Mocker exception.
-rw-r--r--mocker.py3
-rwxr-xr-xtest.py15
2 files changed, 17 insertions, 1 deletions
diff --git a/mocker.py b/mocker.py
index 3b24111..ac6d1d5 100644
--- a/mocker.py
+++ b/mocker.py
@@ -2020,6 +2020,7 @@ class Patcher(Task):
try:
return unpatched(*action.args, **action.kwargs)
except AttributeError:
+ type, value, traceback = sys.exc_info()
if action.kind == "getattr":
# The normal behavior of Python is to try __getattribute__,
# and if it raises AttributeError, try __getattr__. We've
@@ -2031,7 +2032,7 @@ class Patcher(Task):
pass
else:
return __getattr__(*action.args, **action.kwargs)
- raise
+ raise type, value, traceback
class PatchedMethod(object):
diff --git a/test.py b/test.py
index e98acb8..2647141 100755
--- a/test.py
+++ b/test.py
@@ -3983,6 +3983,21 @@ class PatcherTest(TestCase):
self.assertEquals(obj.method(), "original")
self.assertRaises(AssertionError, obj.method)
+ def test_original_exception_raised(self):
+ class C(object):
+ def use_non_existing_attribute(self):
+ return self.bad_attribute
+
+ mock = self.mocker.patch(C)
+ mock.any_other_method()
+ self.mocker.replay()
+ obj = C()
+ try:
+ obj.use_non_existing_attribute()
+ except AttributeError, error:
+ message = "'C' object has no attribute 'bad_attribute'"
+ self.assertEquals(message, error.message)
+
def main():
try: