bpo-23078: Add support for {class,static}method to mock.create_autospec() (GH-11613)

Co-authored-by: Felipe <felipe.nospam.ochoa@gmail.com>
This commit is contained in:
Xtreak 2019-04-22 08:00:23 +05:30 committed by Berker Peksag
parent 9541bd321a
commit 9b21856b0f
5 changed files with 81 additions and 2 deletions

View file

@ -1419,6 +1419,23 @@ class MockTest(unittest.TestCase):
m = mock.create_autospec(object(), name='sweet_func')
self.assertIn('sweet_func', repr(m))
#Issue23078
def test_create_autospec_classmethod_and_staticmethod(self):
class TestClass:
@classmethod
def class_method(cls):
pass
@staticmethod
def static_method():
pass
for method in ('class_method', 'static_method'):
with self.subTest(method=method):
mock_method = mock.create_autospec(getattr(TestClass, method))
mock_method()
mock_method.assert_called_once_with()
self.assertRaises(TypeError, mock_method, 'extra_arg')
#Issue21238
def test_mock_unsafe(self):
m = Mock()