bpo-17185: Add __signature__ to mock that can be used by inspect for signature (GH11125)
* Fix partial and partial method signatures in mock
* Add more calls
* Add NEWS entry
* Use assertEquals and fix markup in NEWS
* Refactor branching and add markup reference for functools
* Revert partial object related changes and fix pr comments
(cherry picked from commit f7fa62ef4422c9deee050a794fd8504640d9f8f4)
Co-authored-by: Xtreak <tirkarthi@users.noreply.github.com>
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index f641e38..5907e5c 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -102,6 +102,7 @@
sig.bind(*args, **kwargs)
_copy_func_details(func, checksig)
type(mock)._mock_check_sig = checksig
+ type(mock).__signature__ = sig
def _copy_func_details(func, funcopy):
@@ -171,11 +172,11 @@
return mock(*args, **kwargs)""" % name
exec (src, context)
funcopy = context[name]
- _setup_func(funcopy, mock)
+ _setup_func(funcopy, mock, sig)
return funcopy
-def _setup_func(funcopy, mock):
+def _setup_func(funcopy, mock, sig):
funcopy.mock = mock
# can't use isinstance with mocks
@@ -223,6 +224,7 @@
funcopy.assert_called = assert_called
funcopy.assert_not_called = assert_not_called
funcopy.assert_called_once = assert_called_once
+ funcopy.__signature__ = sig
mock._mock_delegate = funcopy