diff -r 8d09ec0ee934 Doc/library/unittest.mock.rst --- a/Doc/library/unittest.mock.rst Sat Aug 20 17:31:07 2016 -0400 +++ b/Doc/library/unittest.mock.rst Sun Aug 21 02:24:17 2016 +0200 @@ -1900,6 +1900,12 @@ >>> m.mock_calls == kall.call_list() True +.. note:: + + `"__wrapped__"` can not be used as a method name on `call` objects, otherwise + it would make `inspect.unwrap` loop indefinitely (prohibiting `call` objects + from being present at module level when running doctests). + .. _calls-as-tuples: A ``call`` object is either a tuple of (positional args, keyword args) or diff -r 8d09ec0ee934 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Sat Aug 20 17:31:07 2016 -0400 +++ b/Lib/unittest/mock.py Sun Aug 21 02:24:17 2016 +0200 @@ -1951,6 +1951,10 @@ _Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3) If the _Call has no name then it will match any name. + + .. note:: `__wrapped__` can not be used as a `_Call` method name, and will + always raise `AttributeError`. + """ def __new__(cls, value=(), name=None, parent=None, two=False, from_kall=True): @@ -2055,6 +2059,11 @@ def __getattr__(self, attr): + if attr == '__wrapped__': + raise AttributeError( + "__wrapped__ can not be used as a method name." + "(see issue #25532)" + ) if self.name is None: return _Call(name=attr, from_kall=False) name = '%s.%s' % (self.name, attr) diff -r 8d09ec0ee934 Lib/unittest/test/testmock/testcallable.py --- a/Lib/unittest/test/testmock/testcallable.py Sat Aug 20 17:31:07 2016 -0400 +++ b/Lib/unittest/test/testmock/testcallable.py Sun Aug 21 02:24:17 2016 +0200 @@ -146,6 +146,5 @@ self.assertRaises(TypeError, mock.wibble, 'some', 'args') - if __name__ == "__main__": unittest.main() diff -r 8d09ec0ee934 Lib/unittest/test/testmock/testhelpers.py --- a/Lib/unittest/test/testmock/testhelpers.py Sat Aug 20 17:31:07 2016 -0400 +++ b/Lib/unittest/test/testmock/testhelpers.py Sun Aug 21 02:24:17 2016 +0200 @@ -246,6 +246,8 @@ self.assertEqual(mock.method_calls, [call.foo(1, 2, 3), call.bar.baz(a=3, b=6)]) + def test_no_wrapped_attribute(self): + self.assertFalse(hasattr(call, '__wrapped__')) def test_extended_call(self): result = call(1).foo(2).bar(3, a=4)