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
{{ message }}
Repository navigation
Mocks created by mocker.patch.multiple are not handled like other patches #638
mocker.patch.multiple() returns a dict of the mocks it created, and pytest-mock only registers that dict. #629 made resetall() reset the mocks inside it, but two other features still treat the dict as the mock:
No context-manager warning. The PytestMockWarning hook is only installed on the dict (where it does nothing), not on the mocks:
deftest_multiple_warning(mocker):
mocks=mocker.patch.multiple(Target, a=mocker.DEFAULT)
withpytest.warns(PytestMockWarning): # fails: DID NOT WARNwithmocks["a"]:
pass
with mocker.patch.object(Target, "a"): does warn.
mocker.stop() can't stop a single mock.
deftest_multiple_stop_one(mocker):
mocks=mocker.patch.multiple(Target, a=mocker.DEFAULT, b=mocker.DEFAULT)
mocker.stop(mocks["a"]) # ValueError: This mock object is not registered
Only mocker.stop(mocks) works, which undoes all of them. Supporting single mocks would need each attribute's patcher to be stopped on its own.
Both reproduced on 3.16.1 (Target is any class with attributes a and b).
Activity