Laurent De Buyst added the comment:
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...
--
nosy: +Laurent.De.Buyst
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18622
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com