我在代码中有一个函数被调用两次。
get_user_settings
一旦它在我正在测试的函数中被调用,第二次一些不同的模块有一个再次调用它的函数。
我用这样的pymox嘲笑它:
mox = mox.Mox()
mox.StubOutWithMock(utils, "get_user_settings")
utils.get_user_settings("config").AndReturn(mocked_data)
模拟适用于我的测试代码的第一次调用,但是当它在utils模块中再次被调用时,我得到以下错误
======================================================================
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