Issue #23310: Fix MagicMock's initializer to work with __methods__.

Behavior equivalent to m.configure_mock().  Patch by Kasia Jachim.
This commit is contained in:
Łukasz Langa 2015-04-14 00:12:57 -07:00
parent 4882cacab6
commit 5f6684efe0
4 changed files with 22 additions and 2 deletions

View file

@ -1771,14 +1771,15 @@ def _set_return_value(mock, method, name):
class MagicMixin(object):
def __init__(self, *args, **kw):
self._mock_set_magics() # make magic work for kwargs in init
_safe_super(MagicMixin, self).__init__(*args, **kw)
self._mock_set_magics()
self._mock_set_magics() # fix magic broken by upper level init
def _mock_set_magics(self):
these_magics = _magics
if self._mock_methods is not None:
if getattr(self, "_mock_methods", None) is not None:
these_magics = _magics.intersection(self._mock_methods)
remove_magics = set()