我正在调用unittest的Mock.assert_Called_with(),并且在预期的调用和实际的调用似乎相同的情况下,出现以下错误。 (差异显示没有差异。)这是预期的行为吗?有什么建议吗?
错误:
DELETE FROM *TableNameWithTheRecords*
WHERE *UniqueID* = (SELECT *UniqueID* FROM *TableNameWithTheRecords* WHERE RANK <> 1)
测试代码(这是失败的最后一个assert_call_with):
E AssertionError: Expected call: tabular_learner(<MagicMock name='TabularList.from_df().split_by_idx().label_from_df().databunch()' id='139820374227096'>, callback_fns=[functools.partial(<class 'fastai.callbacks.tracker.TrackerCallback'>, monitor='exp_rmspe'), functools.partial(<class 'fastai.callbacks.tracker.EarlyStoppingCallback'>, mode='min', monitor='exp_rmspe', min_delta=0.01, patience=1), functools.partial(<class 'fastai.callbacks.tracker.SaveModelCallback'>, monitor='exp_rmspe', mode='min', every='improvement', name='2019-03-05-16:32:30')], emb_drop=0.01, layers=[100, 100], metrics=<function exp_rmspe at 0x7f2a79504488>, ps=[0.001, 0.01], y_range=None)
E Actual call: tabular_learner(<MagicMock name='TabularList.from_df().split_by_idx().label_from_df().databunch()' id='139820374227096'>, callback_fns=[functools.partial(<class 'fastai.callbacks.tracker.TrackerCallback'>, monitor='exp_rmspe'), functools.partial(<class 'fastai.callbacks.tracker.EarlyStoppingCallback'>, mode='min', monitor='exp_rmspe', min_delta=0.01, patience=1), functools.partial(<class 'fastai.callbacks.tracker.SaveModelCallback'>, monitor='exp_rmspe', mode='min', every='improvement', name='2019-03-05-16:32:30')], emb_drop=0.01, layers=[100, 100], metrics=<function exp_rmspe at 0x7f2a79504488>, ps=[0.001, 0.01], y_range=None)
答案 0 :(得分:0)
如果您对回调函数是否相等不感兴趣,则可以在断言中为该特定参数提供unittest.mock.ANY
。例如:
from unittest.mock import ANY
...
mock_tabular_learner.assert_called_with(
mock_tabular_list.from_df().split_by_idx().label_from_df().
databunch(),
layers=[100, 100],
ps=[0.001, 0.01],
emb_drop=0.01,
metrics=exp_rmspe,
y_range=None,
callback_fns=ANY) # We don't care about the callback functions