diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 315b611..4203796 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -155,7 +155,7 @@ def _set_signature(mock, original, instance=False): skipfirst = isinstance(original, type) result = _get_signature_object(original, instance, skipfirst) if result is None: - return + return mock func, sig = result def checksig(*args, **kwargs): sig.bind(*args, **kwargs) diff --git a/Lib/unittest/test/testmock/testhelpers.py b/Lib/unittest/test/testmock/testhelpers.py index d5f9e7c..55cd1aa 100644 --- a/Lib/unittest/test/testmock/testhelpers.py +++ b/Lib/unittest/test/testmock/testhelpers.py @@ -1,3 +1,4 @@ +import time import unittest from unittest.mock import ( @@ -891,6 +892,18 @@ class TestCallList(unittest.TestCase): self.assertNotIn(call('fish'), mock.call_args_list) self.assertNotIn([call('fish')], mock.call_args_list) + def test_autospec_on_bound_builtin_function(self): + meth = six.create_bound_method(time.ctime, time.time()) + self.assertIsInstance(meth(), str) + mocked = create_autospec(meth) + + # no signature, so no spec to check against + mocked() + mocked.assert_called_once_with() + mocked.reset_mock() + mocked(4, 5, 6) + mocked.assert_called_once_with(4, 5, 6) + def test_call_list_str(self): mock = Mock()