Message208029
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... |
|
Date |
User |
Action |
Args |
2014-01-13 15:52:23 | Laurent.De.Buyst | set | recipients:
+ Laurent.De.Buyst, michael.foord, nicola.palumbo |
2014-01-13 15:52:23 | Laurent.De.Buyst | set | messageid: <1389628343.54.0.333034006338.issue18622@psf.upfronthosting.co.za> |
2014-01-13 15:52:23 | Laurent.De.Buyst | link | issue18622 messages |
2014-01-13 15:52:23 | Laurent.De.Buyst | create | |
|