New submission from Richard Wise <[email protected]>:
I am trying to use wraps to delegate a call to a decorated patch mock to
another method. By examining the source code, I was able to achieve this using
the (apparently undocumented) `Mock._mock_wraps` attribute instead of the
`wraps` attribute which would be expected given the constructor parameter
names. I find this behaviour very confusing and inconsistent. Can we either
expose `Mock.wraps` attribute or document `_mock_wraps` accordingly?
Example:
class MockRepro(unittest.TestCase)
@patch('foo')
def test_side_effect(self, mock_foo):
# Set side effect in constructor as per
https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock
Mock(side_effect = [1, 2])
# Or can set on decorated patch
foo.side_effect = [1, 2]
@patch('foo')
def test_wraps(self, mock_foo):
def wrapped_method():
return 3
# Set wraps in constructor as per
https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock
Mock(wraps=wrapped_method)
# Or can set on decorated patch
foo.wraps = wrapped_method # This silently fails
foo._mock_wraps = wrapped_method # Where does `_mock_wraps` come from?
----------
components: Library (Lib)
messages: 387397
nosy: Woodz
priority: normal
severity: normal
status: open
title: Mock `_mock_wraps` is undocumented and inconsistently named
versions: Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue43273>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com