mocking - python mock.mock_reset() returns mock instead of resetting the mock -
while using mock library, i've encountered situation calling my_mock.reset_mock()
method returns new mock
instance instead of resetting my_mock
. apparently i'm somehow masking mock.reset_mock()
, cannot figure out how happened.
sample run (python 2.7):
>>> mocks.normal_mock.mock_calls out[6]: [] >>> mocks.normal_mock.reset_mock() >>> mocks.normal_mock.mock_calls out[8]: [] >>> mocks.abnormal_mock.mock_calls out[2]: [] >>> mocks.abnormal_mock.reset_mock() >>> <magicmock name='abnormal_mock.reset_mock()' id='157604104'> >>> mocks.abnormal_mock.mock_calls out[4]: [call.reset_mock()]
any idea cause this?
additional info:
- all mocks encapsulated in designated class, instantiated once, , reset between test in
unittest.testcase.teardown()
. - all mocks created calling
patch.start()
on patched object/method/module - both normal , abnormal mocks in example mock-out module imported uut (a different module each)
found issue.
due convoluted way of mock creation, calling patch()
on patched module, namely, patching mock()
object. since autospec
true
patch call, mock_reset()
patched.
the solution simplify mock creation flow.
Comments
Post a Comment