我试图模仿两个bulk_create
和{
@mock.patch.object(SomeModel.objects, 'bulk_create')
@mock.patch.object(SomeModel, 'save')
def a_dry_run(mocked_bulk_create, mocked_save):
def print_bulk(obj_list):
print 'doing bulk_create'
for obj in obj_list:
print obj
def print_save(instance):
print 'doing save'
print instance
mocked_bulk_create.side_effect = print_bulk
mocked_bulk_create.return_value = True
mocked_save.side_effect = print_save
mocked_save.return_value = True
问题是当我做bulk_create
而不是print_bulk
时,它执行print_save
。我该怎么解决这个问题呢?还是有更干净的方法来解决这个问题?在
争论的顺序应该颠倒过来。正如您在Quick Guidewhere description
patch
中看到的,传递给函数的模拟参数的顺序从下到上遵循patch
的修饰符。在在这种情况下,只需更改修补程序顺序或函数签名,如
相关问题 更多 >
编程相关推荐