mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
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:
parent
9541bd321a
commit
9b21856b0f
5 changed files with 81 additions and 2 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue