Issue43273
Created on 2021-02-20 08:44 by Woodz, last changed 2021-02-27 02:33 by terry.reedy.
Messages (2) | |||
---|---|---|---|
msg387397 - (view) | Author: Richard Wise (Woodz) | Date: 2021-02-20 08:44 | |
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? |
|||
msg387760 - (view) | Author: Terry J. Reedy (terry.reedy) * ![]() |
Date: 2021-02-27 02:33 | |
Private attributes are not documented because they are private and subject to change. Their use is at one's own risk. I don't know mock well enough to understand 'inconsistent' or comment on the change proposal. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2021-02-27 02:33:48 | terry.reedy | set | nosy:
+ terry.reedy messages: + msg387760 |
2021-02-20 08:44:25 | Woodz | create |