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

@ -51,6 +51,14 @@ class Foo(object):
pass
foo = 'bar'
@staticmethod
def static_method():
return 24
@classmethod
def class_method(cls):
return 42
class Bar(object):
def a(self):
pass
@ -1023,6 +1031,18 @@ class PatchTest(unittest.TestCase):
self.assertEqual(result, 3)
def test_autospec_staticmethod(self):
with patch('%s.Foo.static_method' % __name__, autospec=True) as method:
Foo.static_method()
method.assert_called_once_with()
def test_autospec_classmethod(self):
with patch('%s.Foo.class_method' % __name__, autospec=True) as method:
Foo.class_method()
method.assert_called_once_with()
def test_autospec_with_new(self):
patcher = patch('%s.function' % __name__, new=3, autospec=True)
self.assertRaises(TypeError, patcher.start)