diff -r b6ea3dc89a78 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Sat Jan 17 18:46:10 2015 +0200 +++ b/Lib/unittest/mock.py Thu Jan 22 11:06:39 2015 +0200 @@ -2120,7 +2120,8 @@ # descriptors don't have a spec # because we don't know what type they return _kwargs = {} - elif not _callable(spec): + elif not _callable(spec) and not isinstance(spec, (classmethod, + staticmethod)): Klass = NonCallableMagicMock elif is_type and instance and not _instance_callable(spec): Klass = NonCallableMagicMock diff -r b6ea3dc89a78 Lib/unittest/test/testmock/testmock.py --- a/Lib/unittest/test/testmock/testmock.py Sat Jan 17 18:46:10 2015 +0200 +++ b/Lib/unittest/test/testmock/testmock.py Thu Jan 22 11:06:39 2015 +0200 @@ -1187,6 +1187,18 @@ m = mock.create_autospec(object(), name='sweet_func') self.assertIn('sweet_func', repr(m)) + #Issue23078 + def test_create_autospec_classmethod_staticmethod(self): + funcs = [ + staticmethod(lambda obj: obj), + classmethod(lambda obj: obj), + ] + + for func in funcs: + func_mock = mock.create_autospec(func) + func_mock(2, 3) + self.assertEqual(func_mock.mock_calls, [call(2, 3)]) + #Issue21238 def test_mock_unsafe(self): m = Mock() diff -r b6ea3dc89a78 Lib/unittest/test/testmock/testpatch.py --- a/Lib/unittest/test/testmock/testpatch.py Sat Jan 17 18:46:10 2015 +0200 +++ b/Lib/unittest/test/testmock/testpatch.py Thu Jan 22 11:06:39 2015 +0200 @@ -50,6 +50,14 @@ pass foo = 'bar' + @staticmethod + def a_static(): + return 24 + + @classmethod + def a_class(cls): + return 42 + class Bar(object): def a(self): pass @@ -991,6 +999,16 @@ self.assertEqual(result, 3) + def test_autospec_static_class_method(self): + with patch('%s.Foo.a_static' % __name__, autospec=True) as static: + static(24) + self.assertEqual(static.mock_calls, [call(24)]) + + with patch('%s.Foo.a_class' % __name__, autospec=True) as clsmethod: + clsmethod(42) + self.assertEqual(clsmethod.mock_calls, [call(42)]) + + def test_autospec_with_new(self): patcher = patch('%s.function' % __name__, new=3, autospec=True) self.assertRaises(TypeError, patcher.start)