diff -r 37a07cee5969 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Sat Dec 05 17:05:23 2015 -0800 +++ b/Lib/unittest/mock.py Sun Jan 17 20:31:07 2016 +0900 @@ -444,6 +444,7 @@ _eat_self=False): _spec_class = None _spec_signature = None + _spec_code = None if spec is not None and not _is_list(spec): if isinstance(spec, type): @@ -453,6 +454,8 @@ res = _get_signature_object(spec, _spec_as_instance, _eat_self) _spec_signature = res and res[1] + if inspect.isfunction(spec): + _spec_code = spec.__code__ spec = dir(spec) @@ -461,6 +464,7 @@ __dict__['_spec_set'] = spec_set __dict__['_spec_signature'] = _spec_signature __dict__['_mock_methods'] = spec + __dict__['__code__'] = _spec_code def __get_return_value(self):