mocking a function called multiple times using pymox

273 views Asked by At

I have a function in the code that is being called twice. get_user_settings once it is getting called in the function I am testing and second time some different module has a function that calls it again.

I have mocked it using pymox like this:

mox = mox.Mox()
mox.StubOutWithMock(utils, "get_user_settings")
utils.get_user_settings("config").AndReturn(mocked_data)

the mocking works for the first call from my test code but when it gets called again in the utils module I get the below error

======================================================================
FAIL: test_uncommited_changes (test_scmCommandBase.TestSCMCommandBase)
----------------------------------------------------------------------
Traceback (most recent call last):
   File "/local/ciasto/git/myproject/tests/test_scmCommandBase.py", line
79, in test_uncommited_changes
     branch.rebase()
   File "/local/ciasto/git/myproject/bin/local/cmds/update/core.py",
line 81, in rebase
     _utils.save_branch_signature_to_config(user_branch)
   File "/local/ciasto/git/myproject/bin/local/config/utils.py", line
146, in save_branch_signature_to_config
     content = get_user_settings(project_config)
   File "/sw/thirdparty/pymox/0.7.6-bfx1/lib/mox.py", line 886, in __call__
     return mock_method(*params, **named_params)
   File "/sw/thirdparty/pymox/0.7.6-bfx1/lib/mox.py", line 1193, in __call__
     expected_method = self._VerifyMethodCall()
   File "/sw/thirdparty/pymox/0.7.6-bfx1/lib/mox.py", line 1246, in
_VerifyMethodCall
     expected = self._PopNextMethod()
   File "/sw/thirdparty/pymox/0.7.6-bfx1/lib/mox.py", line 1232, in
_PopNextMethod
     raise exception
UnexpectedMethodCallError: Unexpected method call
function.__call__('/tmp/tmpbNI_L4/.myproject') -> None
0

There are 0 answers