You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/voidspace'closed_at=<Date2014-04-15.21:22:29.474>created_at=<Date2014-04-15.15:54:31.458>labels= ['type-bug']
title="unittest.mock.patch.stopall intermittently doesn't work when the same thing is patched multiple times"updated_at=<Date2014-04-15.21:22:29.472>user='https://github.com/voidspace'
What is the expected output? What do you see instead?
I would expect the output from above to be:
'firstmock'
'secondmock'
'hello'
Instead, sometimes it comes out as:
'firstmock'
'secondmock'
'firstmock'
This result is non-deterministic though so it may also come out as expected. Re-run several times to get the error.
This is a result of using a set to store the active patches. Conversion from a set to a list is non-deterministic because the set has no notion of order.
Please provide any additional information below.
This use case may seem strange, but it shows up in large unit tests where a base class sets up a default patch to catch external calls or something similar and then an individual unit test requiring specific mock behavior patches it differently.
I have a patch here that fixes the problem using a list to store the patches to maintain order and call them in reverse order to stop them in the correct order.
New changeset 727b7e9c40e3 by Michael Foord in branch '3.4':
Closes bpo-21239. unittest.mock.patch.stopall() did not work deterministically when the same name was patched multiple times. http://hg.python.org/cpython/rev/727b7e9c40e3
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: