我在代码中有一个被调用两次的函数。
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