提问人:ifrj 提问时间:7/16/2023 最后编辑:quamranaifrj 更新时间:7/16/2023 访问量:96
为什么我在使用 mock 的副作用时会收到“StopIteration”错误?
Why am I getting a 'StopIteration' error when using mock's side effect?
问:
请参阅下面的我的函数,它使用函数,我试图模拟并使用它为两个函数调用分配不同的值。Path
side_effect
def some_function(input_file, file):
compressed_file = Path(input_file)
non_compressed_file = Path(file)
@mock.patch('exchanges.impl.bmex.preprocessing.Path')
def test_choose_MFII_files(mock_Path):
mock_Path.side_effect = [Path(pd.jobserve_config[BMLL_SECTION][WORK_DIR]+ '/MDPRECVOLTICK_MC_20230703.ZIP'),
Path(pd.jobserve_config[BMLL_SECTION][WORK_DIR] + '/MERGED_MDPRECVOLTICK_MC_20230703.ZIP')]
当我运行上述操作时,我得到:
_mock_self = <MagicMock name='Path' id='140495179866752'>, args = (PosixPath('/tmp'), 'MERGED_MDPRECVOLTICK_MC_20230703.ZIP'), kwargs = {}
self = <MagicMock name='Path' id='140495179866752'>, effect = <list_iterator object at 0x7fc7954ae220>
def _execute_mock_call(_mock_self, *args, **kwargs):
self = _mock_self
# separate from _increment_mock_call so that awaited functions are
# executed separately from their call, also AsyncMock overrides this method
effect = self.side_effect
if effect is not None:
if _is_exception(effect):
raise effect
elif not _callable(effect):
> result = next(effect)
E StopIteration
../../anaconda3/envs/jobserveee/lib/python3.8/site-packages/mock/mock.py:1163: StopIteration
知道为什么会这样吗?
答: 暂无答案
评论
side_effect