Repository navigation
Handle patch.multiple mocks individually - #655
mehdimirzafaruk wants to merge 3 commits into
Conversation
| patchers = [patcher, *patcher.additional_patchers] | ||
| patcher.additional_patchers = [] | ||
| mocked = {} | ||
| for patcher in patchers: |
There was a problem hiding this comment.
one edge case w/ starting these patchers separately: if the second or third patch fails, the earlier ones have already been applied. unlike the original combined patcher, this path doesn't roll them back before raising. could we clean up the patchers started by this call on failure? a test where one target is invalid after a valid one would cover it.
There was a problem hiding this comment.
Good catch, thank you! Added rollback cleanup on failure so earlier patchers started during the call are stopped and unregistered before re-raising, along with a regression test for an invalid target attribute.
There was a problem hiding this comment.
that's the failure case I was worried about. the earlier patches get rolled back now instead of being left active. good fix!
patch.multiplecurrently registers its result dictionary rather than the individual mocks. This means the context-manager warning is not installed andmocker.stop()cannot stop one returned mock.Register each underlying patch separately while preserving the returned dictionary of mocks. This also keeps
resetall()andstopall()behavior consistent with other patch helpers.Tests:
tox -e py312;pre-commit run --all-filesFixes #638