diff options
author | Xtreak <tir.karthi@gmail.com> | 2019-04-22 08:00:23 +0530 |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2019-04-22 05:30:23 +0300 |
commit | 9b21856b0fcda949de239edc7aa6cf3f2f4f77a3 (patch) | |
tree | 67b8f216a06b29748f5e573d5ab855b3462752e7 /Lib/unittest/test/testmock/testpatch.py | |
parent | 9541bd321a94f13dc41163a5d7a1a847816fac84 (diff) | |
download | cpython-git-9b21856b0fcda949de239edc7aa6cf3f2f4f77a3.tar.gz |
bpo-23078: Add support for {class,static}method to mock.create_autospec() (GH-11613)
Co-authored-by: Felipe <felipe.nospam.ochoa@gmail.com>
Diffstat (limited to 'Lib/unittest/test/testmock/testpatch.py')
-rw-r--r-- | Lib/unittest/test/testmock/testpatch.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testpatch.py b/Lib/unittest/test/testmock/testpatch.py index 2c14360b2d..51c66fec67 100644 --- a/Lib/unittest/test/testmock/testpatch.py +++ b/Lib/unittest/test/testmock/testpatch.py @@ -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) |