This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Attaching a PropertyMock records calls
Type: behavior Stage: needs patch
Components: Library (Lib) Versions: Python 3.4, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: eric.araujo, kushal.das, michael.foord, xtreak
Priority: normal Keywords:

Created on 2014-04-16 16:19 by michael.foord, last changed 2022-04-11 14:58 by admin.

Messages (3)
msg216488 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2014-04-16 16:19
What steps will reproduce the problem?

    >>> foo = Mock(name='foo')
    >>> prop = PropertyMock(name='prop')
    >>> type(foo).prop = prop
    >>> foo.attach_mock(prop, 'prop')
    >>> foo.mock_calls
    [call.prop(<PropertyMock name='foo.prop' id='4300017296'>)]

Expected:

    >>> foo.mock_calls
    []

What version of the product are you using? On what operating system?

    % pip freeze | grep mock
    mock==1.0.1

    OS X 10.8.4

Please provide any additional information below.

    It would be even cooler if attaching a property mock made calls to the property appear in the mock_calls for the hosting mock without having to attach it, the way it does with a non-property method :)

    I use mock every day now and am firmly of the opinion it is far, far more awesome than sliced bread. Thanks for making it available to the Python community :)
msg216603 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2014-04-16 21:40
>>> type(foo).prop = prop
    >>> foo.attach_mock(prop, 'prop')

Are both of these lines needed?
msg217006 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2014-04-22 14:15
Not sure, but I guess it would be easy to find out. It will need some digging into to find out where the actual bug is. It shouldn't be hard to find though.
History
Date User Action Args
2022-04-11 14:58:01adminsetgithub: 65454
2020-02-18 09:21:36xtreaksetnosy: + xtreak
2014-04-22 14:15:43michael.foordsetmessages: + msg217006
2014-04-16 21:40:20eric.araujosetnosy: + eric.araujo
messages: + msg216603
2014-04-16 16:19:15michael.foordcreate