[issue43273] Mock `_mock_wraps` is undocumented and inconsistently named

2021-02-26 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

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.

--
nosy: +terry.reedy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43273] Mock `_mock_wraps` is undocumented and inconsistently named

2021-02-20 Thread Richard Wise


New submission from Richard Wise :

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com