summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test/testmock/testhelpers.py
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2012-04-13 16:39:16 (GMT)
committerMichael Foord <michael@voidspace.org.uk>2012-04-13 16:39:16 (GMT)
commit656319e58d80478c7aa2a783606f0b50053529ae (patch)
tree80e54a5ab0f5bac83555ca929453bb5292ce18ec /Lib/unittest/test/testmock/testhelpers.py
parent899ee613f7b4a4f5967943095d5fbc9522356ad3 (diff)
downloadcpython-656319e58d80478c7aa2a783606f0b50053529ae.zip
cpython-656319e58d80478c7aa2a783606f0b50053529ae.tar.gz
cpython-656319e58d80478c7aa2a783606f0b50053529ae.tar.bz2
Make unittest.mock.create_autospec resilient against AttributeError on original object
Diffstat (limited to 'Lib/unittest/test/testmock/testhelpers.py')
-rw-r--r--Lib/unittest/test/testmock/testhelpers.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testhelpers.py b/Lib/unittest/test/testmock/testhelpers.py
index a2ed100..4c43f87 100644
--- a/Lib/unittest/test/testmock/testhelpers.py
+++ b/Lib/unittest/test/testmock/testhelpers.py
@@ -651,6 +651,29 @@ class SpecSignatureTest(unittest.TestCase):
mock.f.assert_called_with(3, 4)
+ def test_skip_attributeerrors(self):
+ class Raiser(object):
+ def __get__(self, obj, type=None):
+ if obj is None:
+ raise AttributeError('Can only be accessed via an instance')
+
+ class RaiserClass(object):
+ raiser = Raiser()
+
+ @staticmethod
+ def existing(a, b):
+ return a + b
+
+ s = create_autospec(RaiserClass)
+ self.assertRaises(TypeError, lambda x: s.existing(1, 2, 3))
+ s.existing(1, 2)
+ self.assertRaises(AttributeError, lambda: s.nonexisting)
+
+ # check we can fetch the raiser attribute and it has no spec
+ obj = s.raiser
+ obj.foo, obj.bar
+
+
def test_signature_class(self):
class Foo(object):
def __init__(self, a, b=3):