Tuesday, 20 August 2013

python mock.mock_reset() returns mock instead of resetting the mock

python mock.mock_reset() returns mock instead of resetting the mock

While using the mock library, I've encountered a situation where calling
my_mock.reset_mock() method returns a new Mock instance instead of
resetting the my_mock. Apparently I'm somehow masking Mock.reset_mock(),
but I cannot figure out how this 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()
>>> mocks.abnormal_mock.mock_calls
Out[4]: [call.reset_mock()]
Any idea what could cause this?

No comments:

Post a Comment