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.

Author Laurent.De.Buyst
Recipients Laurent.De.Buyst, michael.foord, nicola.palumbo
Date 2014-01-13.15:52:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1389628343.54.0.333034006338.issue18622@psf.upfronthosting.co.za>
In-reply-to
Content
The proposed patch does solve the infinite recursion bug, but a different problem appears when resetting the same mock multiple times: it only works the first time.

Using the patch as it stands:

>>> from unittest.mock import mock_open
>>> mo = mock_open()
>>> a = mo()
>>> mo.call_count
1
>>> mo.reset_mock()
>>> mo.call_count
0
>>> b = mo()
>>> mo.call_count
1
>>> mo.reset_mock()
>>> mo.call_count
1

And here from a version with an added print(visited) statement:

>>> from unittest.mock import mock_open
>>> mo = mock_open()
>>> a = mo()
>>> mo.call_count
1
>>> mo.reset_mock()
[]
[139803191795152]
[139803191795152, 139803181189008]
[139803191795152, 139803181189008, 139803213598416]
[139803191795152, 139803181189008, 139803213598416, 139803213652048]
[139803191795152, 139803181189008, 139803213598416, 139803213652048]
>>> mo.call_count
0
>>> b = mo()
>>> mo.call_count
1
>>> mo.reset_mock()
[139803191795152, 139803181189008, 139803213598416, 139803213652048, 139803213598288]
>>> mo.call_count
1
>>> mo.reset_mock(visited=[])
[]
[139803191795152]
[139803191795152, 139803181189008]
[139803191795152, 139803181189008, 139803213598416]
[139803191795152, 139803181189008, 139803213598416, 139803213652048]
[139803191795152, 139803181189008, 139803213598416, 139803213652048]
>>> mo.call_count
0

As you can see, for some reason I don't quite grasp, the 'visited' parameter persists across calls to reset_mock(), meaning that the very first call does indeed reset it but subsequent calls do not.

As the last two calls show, one can force a reset by explicitly providing an empty list, but this is starting to become a change in API and not just a bugfix...
History
Date User Action Args
2014-01-13 15:52:23Laurent.De.Buystsetrecipients: + Laurent.De.Buyst, michael.foord, nicola.palumbo
2014-01-13 15:52:23Laurent.De.Buystsetmessageid: <1389628343.54.0.333034006338.issue18622@psf.upfronthosting.co.za>
2014-01-13 15:52:23Laurent.De.Buystlinkissue18622 messages
2014-01-13 15:52:23Laurent.De.Buystcreate