mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-102978: Fix mock.patch function signatures for class and staticmethod decorators (#103228)
Fixes unittest.mock.patch not enforcing function signatures for methods decorated with @classmethod or @staticmethod when patch is called with autospec=True.
This commit is contained in:
parent
19d2639d1e
commit
59e0de4903
5 changed files with 58 additions and 0 deletions
|
@ -952,6 +952,24 @@ class SpecSignatureTest(unittest.TestCase):
|
|||
self.assertFalse(hasattr(autospec, '__name__'))
|
||||
|
||||
|
||||
def test_autospec_signature_staticmethod(self):
|
||||
class Foo:
|
||||
@staticmethod
|
||||
def static_method(a, b=10, *, c): pass
|
||||
|
||||
mock = create_autospec(Foo.__dict__['static_method'])
|
||||
self.assertEqual(inspect.signature(Foo.static_method), inspect.signature(mock))
|
||||
|
||||
|
||||
def test_autospec_signature_classmethod(self):
|
||||
class Foo:
|
||||
@classmethod
|
||||
def class_method(cls, a, b=10, *, c): pass
|
||||
|
||||
mock = create_autospec(Foo.__dict__['class_method'])
|
||||
self.assertEqual(inspect.signature(Foo.class_method), inspect.signature(mock))
|
||||
|
||||
|
||||
def test_spec_inspect_signature(self):
|
||||
|
||||
def myfunc(x, y): pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue